package com.sbs.gaoxinqutoilet.fragment;

import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.widget.ListPopupWindow;
import androidx.appcompat.widget.Toolbar;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import com.bumptech.glide.Glide;
import com.google.gson.reflect.TypeToken;
import com.sbs.gaoxinqutoilet.R;
import com.sbs.gaoxinqutoilet.adapter.CeFangAdapter;
import com.sbs.gaoxinqutoilet.adapter.GaizaoTypeAdapter;
import com.sbs.gaoxinqutoilet.base.BaseBackFragment;
import com.sbs.gaoxinqutoilet.entity.AcceptImageEntity;
import com.sbs.gaoxinqutoilet.entity.AddNewBuildTypeEntity;
import com.sbs.gaoxinqutoilet.entity.AddNewShiGongTeamEntity;
import com.sbs.gaoxinqutoilet.entity.BuildFileItemEntity;
import com.sbs.gaoxinqutoilet.entity.FIleEditSaveUpEntity;
import com.sbs.gaoxinqutoilet.entity.FileDetialEntity;
import com.sbs.gaoxinqutoilet.entity.FileDetialInfoImageEntity;
import com.sbs.gaoxinqutoilet.entity.MenPaiHaoEntity;
import com.sbs.gaoxinqutoilet.entity.MessageEvent;
import com.sbs.gaoxinqutoilet.entity.UploadImageEntity;
import com.sbs.gaoxinqutoilet.eventbus.EventCenter;
import com.sbs.gaoxinqutoilet.eventbus.StartNewFragmentEvent;
import com.sbs.gaoxinqutoilet.http.HttpApis;
import com.sbs.gaoxinqutoilet.http.Request;
import com.sbs.gaoxinqutoilet.interfaces.AddNewShigTeamPopuListener;
import com.sbs.gaoxinqutoilet.interfaces.BuildTypePopuListener;
import com.sbs.gaoxinqutoilet.interfaces.CeFangPopuListener;
import com.sbs.gaoxinqutoilet.interfaces.Constants;
import com.sbs.gaoxinqutoilet.interfaces.DialogClick;
import com.sbs.gaoxinqutoilet.interfaces.PopuClickListener;
import com.sbs.gaoxinqutoilet.myapp.MyApplication;
import com.sbs.gaoxinqutoilet.utils.GsonTools;
import com.sbs.gaoxinqutoilet.utils.HttpUtils;
import com.sbs.gaoxinqutoilet.utils.ImageLoaderUtils;
import com.sbs.gaoxinqutoilet.utils.ImageUtils;
import com.sbs.gaoxinqutoilet.utils.JsonUtil;
import com.sbs.gaoxinqutoilet.utils.LogUtils;
import com.sbs.gaoxinqutoilet.utils.NetTimeUtils;
import com.sbs.gaoxinqutoilet.utils.RegexUtils;
import com.sbs.gaoxinqutoilet.utils.SPUtil;
import com.sbs.gaoxinqutoilet.utils.StringUtil;
import com.sbs.gaoxinqutoilet.utils.appinstallerutils.ConvertUtils;
import com.sbs.gaoxinqutoilet.view.JeScroolView;
import com.zhy.autolayout.AutoLinearLayout;
import com.zhy.autolayout.AutoRelativeLayout;
import com.zhy.http.okhttp.OkHttpUtils;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.Type;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.functions.Consumer;
import io.reactivex.functions.Function;
import io.reactivex.schedulers.Schedulers;
import me.iwf.photopicker.PhotoPicker;
import top.zibin.luban.Luban;


/**
 * Created by 聪明一只哈 on 2018/6/1.
 * Time: 2018/6/1  15:24
 */

public class ToiletFilesDetialFragment extends BaseBackFragment {

    //假数据,传过来的值  存储在Bundle中
    private static final String EDIT_STATE = "edit_state";
    @BindView(R.id.toolbar_back)
    ImageView toolbarBack;
    @BindView(R.id.toolbar_title)
    TextView toolbarTitle;
    @BindView(R.id.toolbar_iv_menu)
    ImageView toolbarIvMenu;
    @BindView(R.id.toolbar_tv_menu)
    TextView toolbarTvMenu;
    @BindView(R.id.toolbar_rl_menu)
    AutoRelativeLayout toolbarRlMenu;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.acceptance_et_address)
    TextView acceptanceEtAddress;
    @BindView(R.id.acceptance_et_doorcode)
    EditText acceptanceEtDoorcode;

    @BindView(R.id.et_hunman_numbers)
    EditText etHunmanNumbers;
    @BindView(R.id.et_file_tel)
    EditText etFileTel;

    @BindView(R.id.acceptance_et_doorname)
    EditText acceptanceEtDoorname;
    @BindView(R.id.acceptance_et_doornumberning)
    TextView acceptanceEtDoornumberning;
    @BindView(R.id.acceptance_et_idnumber)
    EditText acceptanceEtIdnumber;
    @BindView(R.id.acceptance_tv_isIdel)
    TextView acceptanceTvIsIdel;
    @BindView(R.id.acceptance_tv_huafeichi)
    TextView acceptance_tv_huaFeiChi;
    @BindView(R.id.acceptance_tv_buildstate)
    TextView acceptanceTvBuildstate;
    @BindView(R.id.acceptance_tv_buildtype)
    TextView acceptanceTvBuildtype;
    @BindView(R.id.acceptance_tv_teamname)
    TextView acceptanceTvTeamname;
    @BindView(R.id.file_bianchi_tv)
    TextView fileBianchiTv;
    @BindView(R.id.file_chongshui_tv)
    TextView fileChongshuiTv;
    @BindView(R.id.file_cefang_tv)
    TextView fileCefangTv;
    @BindView(R.id.acceptance_tv_buildyear)
    TextView acceptanceTvBuildyear;
    @BindView(R.id.arl_click_state)
    RelativeLayout arl_Click_State;
    @BindView(R.id.all_acceptance_stype)
    AutoLinearLayout all_acceptance_stype;
    @BindView(R.id.acceptance_tv_stype)
    TextView acceptance_tv_stype;
    @BindView(R.id.acceptance_bt_save)
    Button acceptanceBtSave;
    @BindView(R.id.my_jescrollview)
    JeScroolView myJescrollview;
    Unbinder unbinder;

    //上传图片与按钮的id
    @BindView(R.id.sell_iv_myFile_three)
    ImageView sellIvMyFileThree;
    @BindView(R.id.sell_iv_myFile_four)
    ImageView sellIvMyFileFour;
    @BindView(R.id.sell_iv_myFile_five)
    ImageView sellIvMyFileFive;
    @BindView(R.id.sell_iv_myFile_one)
    ImageView sellIvMyFileOne;
    @BindView(R.id.sell_iv_myFile_two)
    ImageView sellIvMyFileTwo;
    @BindView(R.id.image_show_b)
    ImageView image_show_B;
    @BindView(R.id.image_show_m)
    ImageView image_show_M;
    @BindView(R.id.image_show_f)
    ImageView image_show_F;
    @BindView(R.id.image_show_id)
    ImageView image_show_ID;
    @BindView(R.id.image_show_d)
    ImageView image_show_D;
    @BindView(R.id.up_all_ing)
    AutoRelativeLayout upAllIng;
    @BindView(R.id.up_all_after)
    AutoRelativeLayout upAllAfter;
    @BindView(R.id.up_all_before)
    AutoRelativeLayout upAllBefore;
    @BindView(R.id.up_all_idpic)
    AutoRelativeLayout upAllIdpic;
    @BindView(R.id.up_all_frontdoor)
    AutoRelativeLayout upAllFrontdoor;


    private static final int REQUEST_CODE_SOME_FEATURES_PERMISSIONS = 111;
    @BindView(R.id.toolbar_iv_add)
    ImageView toolbarIvAdd;
    @BindView(R.id.file_header)
    View fileHeader;
    @BindView(R.id.all_acceptance_address)
    AutoLinearLayout allAcceptanceAddress;
    @BindView(R.id.all_acceptance_doorcode)
    AutoLinearLayout allAcceptanceDoorcode;
    @BindView(R.id.all_acceptance_doorname)
    AutoLinearLayout allAcceptanceDoorname;
    @BindView(R.id.all_human_number)
    AutoLinearLayout allHumanNumber;
    @BindView(R.id.all_file_tel)
    AutoLinearLayout allFileTel;
    @BindView(R.id.all_acceptance_doornumbering)
    AutoLinearLayout allAcceptanceDoornumbering;
    @BindView(R.id.all_acceptance_idnumber)
    AutoLinearLayout allAcceptanceIdnumber;
    @BindView(R.id.v_line_file)
    View vLineFile;
    @BindView(R.id.all_acceptance_isIdel)
    AutoLinearLayout allAcceptanceIsIdel;
    @BindView(R.id.all_acceptance_buildstate)
    AutoLinearLayout allAcceptanceBuildstate;
    @BindView(R.id.all_acceptance_buildyear)
    AutoLinearLayout allAcceptanceBuildyear;
    @BindView(R.id.all_acceptance_buildtype)
    AutoLinearLayout allAcceptanceBuildtype;
    @BindView(R.id.all_acceptance_teamname)
    AutoLinearLayout allAcceptanceTeamname;
    @BindView(R.id.all_acceptance_huafeichi)
    AutoLinearLayout allAcceptanceHuafeichi;
    @BindView(R.id.all_file_spno)
    AutoLinearLayout allFileSpno;
    @BindView(R.id.all_file_chongshui)
    AutoLinearLayout allFileChongshui;
    @BindView(R.id.all_file_cefang)
    AutoLinearLayout allFileCefang;
    @BindView(R.id.image_show_dangan_gaizaotwo)
    ImageView imageShowDanganGaizaotwo;
    @BindView(R.id.sell_iv_dangan_gaizaotwo)
    ImageView sellIvDanganGaizaotwo;
    @BindView(R.id.up_all_dangan_gaizaotwo)
    AutoRelativeLayout upAllDanganGaizaotwo;
    @BindView(R.id.image_show_dangan_gaizaothree)
    ImageView imageShowDanganGaizaothree;
    @BindView(R.id.sell_iv_dangan_gaizaothree)
    ImageView sellIvDanganGaizaothree;
    @BindView(R.id.up_all_dangan_gaizaothree)
    AutoRelativeLayout upAllDanganGaizaothree;
    @BindView(R.id.arl_temp)
    AutoRelativeLayout arlTemp;
    private boolean isShowDialog = true;
    private int mLayoutType = -1;

    //是否闲置
    private ListPopupWindow isIdelPopupWindow;
    List<String> isIdellist = new ArrayList<>();
    //改造状态
    private ListPopupWindow buildstatePopupWindow;
    List<String> buildstatelist = new ArrayList<>();
    //任务年份
    private ListPopupWindow buildYearPopupWindow;
    List<String> buildyearlist = new ArrayList<>();
    List<String> changeStylelist = new ArrayList<>();

    //改造类型
    private ListPopupWindow buildtypePopupWindow;
    //List<String> buildtypelist = new ArrayList<>();
    //施工队伍名称
    private ListPopupWindow TeamNamePopupWindow;
    private BuildFileItemEntity.DataBean getdataBean;
    private FileDetialRequest fileDetialRequest;
    private CommitRequest commitRequest;

    //改造类型
    private List<AddNewBuildTypeEntity> addNewBuildTypeEntityList;
    //施工队伍
    private List<AddNewShiGongTeamEntity> addNewShigongteamEntityList;

    private boolean isUploadSuccess;
    private boolean isImageIdSuccess;
    private boolean isImageDoorFontSuccess;
    private boolean isImageBfSuccess;
    private boolean isImageMidSuccess;
    private boolean isImageAfSuccess;
    private boolean isImageingTwoSuccess;
    private boolean isImageingThreeSuccess;


    private FileDetialInfoImageEntity fdIentity = new FileDetialInfoImageEntity();
    private String[] before_ima = new String[]{null, null, null, null, null, null, null, null,null,null};
    private String[] ing_ima = new String[]{null, null, null, null, null, null, null, null,null,null};
    private String[] after_ima = new String[]{null, null, null, null, null, null, null, null,null,null};
    private String[] idcard_ima = new String[]{null, null, null, null, null, null, null, null,null,null};
    private String[] fodoor_ima = new String[]{null, null, null, null, null, null, null, null,null,null};
    private String[] ing_ima_two = new String[]{null, null, null, null, null, null, null, null,null,null};
    private String[] ing_ima_three = new String[]{null, null, null, null, null, null, null, null,null,null};
    private FileDetialEntity fileDetialEntity;
    private CeFangAdapter myAdapter;
    private ArrayList<AcceptImageEntity> acceptImageEntities;
    private String netTime;
    private ListPopupWindow changStylePopupWindow;
    private String token_data;

    //图片名称除重
    private List<String> imageName=new ArrayList<>();
    private GaizaoTypeAdapter myBuildTypeAdapter;


    public static ToiletFilesDetialFragment newInstance(BuildFileItemEntity.DataBean dataBean) {
        Bundle args = new Bundle();
        args.putSerializable(EDIT_STATE, dataBean);
        ToiletFilesDetialFragment fragment = new ToiletFilesDetialFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_acceptance, container, false);
        unbinder = ButterKnife.bind(this, view);
        image_show_F=view.findViewById(R.id.image_show_f);
        //校验门牌号,初始化
        SPUtil.putString("mph_file", "flag");
        initView(inflater);
        return attachToSwipeBack(view);
    }


    /**
     * 初始化view
     *
     * @param inflater
     */
    private void initView(LayoutInflater inflater) {
        EventBus.getDefault().register(this);

        imageName.clear();
        token_data = SPUtil.getString(Constants.KEY_TOKEN, "");

        toolbarTitle.setText("户厕改造档案");
        //返回按钮
        toolbarBack.setVisibility(View.VISIBLE);
        //设置回键
        initToolbarBack(toolbar);
        Bundle arguments = getArguments();
        if (arguments != null) {
            getdataBean = (BuildFileItemEntity.DataBean) arguments.getSerializable(EDIT_STATE);
            LogUtils.i("editstate", "initView: " + getdataBean.is_edit());
            boolean edit = getdataBean.is_edit();
            if (!edit) {
                //根据传过来的状态设置是否和交互
                //所属地
                acceptanceEtAddress.setEnabled(false);
                //门牌号
                acceptanceEtDoorcode.setEnabled(false);
                //户名
                acceptanceEtDoorname.setEnabled(false);
                //家庭人口
                etHunmanNumbers.setEnabled(false);
                //联系电话
                etFileTel.setEnabled(false);
                //户编号
                acceptanceEtDoornumberning.setEnabled(false);
                //身份证号
                acceptanceEtIdnumber.setEnabled(false);
                //是否闲置
                acceptanceTvIsIdel.setEnabled(false);
                //改造状态
                acceptanceTvBuildstate.setEnabled(false);
                //改造类型
                acceptanceTvBuildtype.setEnabled(false);
                //改厕方式  改造状态为未改造、改造中、已改造时改厕方式字段可编辑。闲置和旧有改造不能编辑
                //acceptance_tv_stype.setEnabled(false);
                //施工队伍名称
                acceptanceTvTeamname.setEnabled(false);
                //化粪池材料
                acceptance_tv_huaFeiChi.setEnabled(false);
                //便池类型
                fileBianchiTv.setEnabled(false);
                //冲水方式
                fileChongshuiTv.setEnabled(false);
                //厕房类型
                fileCefangTv.setEnabled(false);
                //bt
                acceptanceBtSave.setBackgroundResource(R.drawable.toilet_sliding_tv_unselected);
                acceptanceBtSave.setEnabled(false);

                //5张图片
//                image_show_B.setClickable(false);
//                image_show_M.setClickable(false);
//                image_show_F.setClickable(false);
//                image_show_ID.setClickable(false);
//                image_show_D.setClickable(false);

//                upAllBefore.setClickable(false);
//                upAllIng.setClickable(false);
//                upAllAfter.setClickable(false);
//                upAllIdpic.setClickable(false);
//                upAllFrontdoor.setClickable(false);


                //arl_Click_State.setAlpha((float) 0.3);
                arl_Click_State.setVisibility(View.VISIBLE);
                arl_Click_State.setEnabled(false);  //只需如此设置，即可达到效果

            }

        }

        isIdellist.add("是");
        isIdellist.add("否");

        buildstatelist.add("改造中");
        buildstatelist.add("已改造");
        buildstatelist.add("未改造");
        buildstatelist.add("旧有改造");


        buildyearlist.add("2020年之前");
        buildyearlist.add("2020年");

        // 改厕放式 农户自改自建、政府主导统一施工
        changeStylelist.add("农户自改自建");
        changeStylelist.add("政府主导统一施工");

        getNetTimeNow();
    }

    private void getNetTimeNow() {

        new Thread() {
            @Override
            public void run() {
                netTime = NetTimeUtils.getNetTime();
            }
        }.start();

    }


    @OnClick({R.id.acceptance_tv_isIdel, R.id.acceptance_tv_buildstate,
            R.id.acceptance_tv_buildtype, R.id.acceptance_tv_teamname,
            R.id.acceptance_bt_save, R.id.acceptance_tv_stype,
            R.id.up_all_before, R.id.up_all_ing, R.id.up_all_after,
            R.id.up_all_idpic, R.id.up_all_frontdoor,
            R.id.file_bianchi_tv, R.id.file_chongshui_tv, R.id.file_cefang_tv,
            R.id.acceptance_tv_huafeichi, R.id.acceptance_tv_buildyear,
            R.id.up_all_dangan_gaizaotwo,R.id.up_all_dangan_gaizaothree})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            //是否闲置
            case R.id.acceptance_tv_isIdel:
                break;
            //建造状态
            case R.id.acceptance_tv_buildstate:
                buildstatePopupWindow = new ListPopupWindow(_mActivity);
                setPopuData(view, buildstatePopupWindow, buildstatelist);
                setPopuClickListener(new PopuClickListener() {
                    @Override
                    public void show(String mess) {
                        //Toast.makeText(_mActivity, "默认排序是: " + mess, Toast.LENGTH_SHORT).show();
                        acceptanceTvBuildstate.setText(mess);

                        UpShowForState(mess);
                        //isEditableBuildStyle(mess);
                    }
                });
                break;
            //建造类型
            case R.id.acceptance_tv_buildtype:


//                String buildtype_n = acceptanceTvBuildtype.getText().toString().trim();
//                if(TextUtils.isEmpty(buildtype_n)){
//                    getStateType(view);
//                }else{
//                    showAlertDialog(_mActivity,"提示","此操作会清除原有改造类型数据，确认更改吗？",new DialogClick(){
//                        @Override
//                        public void PositiveMessage() {
//                            super.PositiveMessage();
//                            getStateType(view);
//                        }
//
//                        @Override
//                        public void NegativeMessage() {
//                            super.NegativeMessage();
//                        }
//                    });
//
//                }

                getStateType(view);



                break;
            //改厕放式
            case R.id.acceptance_tv_stype:
                changStylePopupWindow = new ListPopupWindow(_mActivity);
                setPopuData(view, changStylePopupWindow, changeStylelist);
                setPopuClickListener(new PopuClickListener() {
                    @Override
                    public void show(String mess) {

                        acceptance_tv_stype.setText(mess);
                        //设置改厕方式字段gaizao_fangshi
                    }
                });

                break;
            //任务年份  2018、2019、2020、2021、2022
            case R.id.acceptance_tv_buildyear:

                buildYearPopupWindow = new ListPopupWindow(_mActivity);
                setPopuData(view, buildYearPopupWindow, buildyearlist);
                setPopuClickListener(new PopuClickListener() {
                    @Override
                    public void show(String mess) {

                        acceptanceTvBuildyear.setText(mess);
                    }
                });
                break;
            //施工队伍名字
            case R.id.acceptance_tv_teamname:
                String area_id = SPUtil.getString(Constants.EDITAREAID, "");
                if (!TextUtils.isEmpty(area_id) && area_id != null) {
                    area_id = area_id.substring(0, 9);
                }
                getShigongTeamData(view, area_id);
                break;
            //化粪池材料
            case R.id.acceptance_tv_huafeichi:
                getHuaFenChiCailiao(view);
                break;
            //便池类型
            case R.id.file_bianchi_tv:
                getBianchiType(view);
                break;
            //冲水方式
            case R.id.file_chongshui_tv:
                getShuichongTYpe(view);
                break;
            //厕房类型
            case R.id.file_cefang_tv:

//                String cefang_n = fileCefangTv.getText().toString().trim();
//                if(TextUtils.isEmpty(cefang_n)){
//                    getCeFangType(view);
//                }else{
//                    showAlertDialog(_mActivity,"提示","此操作会清除原有厕房类型数据，确认更改吗？",new DialogClick(){
//                        @Override
//                        public void PositiveMessage() {
//                            super.PositiveMessage();
//                            getCeFangType(view);
//                        }
//
//                        @Override
//                        public void NegativeMessage() {
//                            super.NegativeMessage();
//                        }
//                    });
//
//                }

                getCeFangType(view);


                break;
            //上传图片
            case R.id.up_all_before:
                //只能预览
                if (!getdataBean.is_edit() && image_show_B.getVisibility() == View.VISIBLE) {
                    GotoImageFg(image_show_B, "改造前");
                } else {
                    mLayoutType = 1;
                    showPhotoPic();
                }
                break;
            case R.id.up_all_ing:
                if (!getdataBean.is_edit() && image_show_M.getVisibility() == View.VISIBLE) {
                    GotoImageFg(image_show_M, "改造中", "重建中1");
                } else {
                    mLayoutType = 2;
                    showPhotoPic();
                }
                break;
            case R.id.up_all_after:
                if (!getdataBean.is_edit() && image_show_F.getVisibility() == View.VISIBLE) {
                    GotoImageFg(image_show_F, "改造后", "重建后");
                } else {
                    mLayoutType = 3;
                    showPhotoPic();
                }
                break;
            case R.id.up_all_idpic:
                if (!getdataBean.is_edit() && image_show_ID.getVisibility() == View.VISIBLE) {
                    GotoImageFg(image_show_ID, "身份证正面", "身份证");
                } else {
                    mLayoutType = 4;
                    showPhotoPic();
                }
                break;
            case R.id.up_all_frontdoor:
                if (!getdataBean.is_edit() && image_show_D.getVisibility() == View.VISIBLE) {
                    GotoImageFg(image_show_D, "大门照");
                } else {
                    mLayoutType = 5;
                    showPhotoPic();
                }
                break;
            //改造中2
            case R.id.up_all_dangan_gaizaotwo:

                if (!getdataBean.is_edit() && imageShowDanganGaizaotwo.getVisibility() == View.VISIBLE) {
                    GotoImageFg(imageShowDanganGaizaotwo, "补充照片1");
                }else{
                    mLayoutType = 6;
                    showPhotoPic();
                }



                break;
            //改造中2
            case R.id.up_all_dangan_gaizaothree:

                if (!getdataBean.is_edit() && imageShowDanganGaizaothree.getVisibility() == View.VISIBLE) {
                    GotoImageFg(imageShowDanganGaizaothree, "补充照片2");
                }else {
                    mLayoutType = 7;
                    showPhotoPic();
                }

                break;

            //保存按钮
            case R.id.acceptance_bt_save:
                //门牌号
                final String menpaihao = acceptanceEtDoorcode.getText().toString().trim();
                if (fileDetialEntity != null && !menpaihao.equals(fileDetialEntity.getMenpaihao())) {
                    //2.
                    if (RegexUtils.getCheckRegex(menpaihao)) {
                        LogUtils.i("展示门牌号", "有符号");
                        showAlertOnlyPos(_mActivity, "门牌号不正确", "门牌号不可输入符号");
                        cancelLoadingDialog();
                        return;
                    } else {
                        showLoadingDialog("校验门牌号...");
                        String village = fileDetialEntity.getArea_id();//所选村的地区ID
                        final String check_menph = HttpApis.addnew_jiaoyanmenph + menpaihao;
                        Map<String, String> params = new HashMap<>();
                        params.put("idvalue", village + ":" + getdataBean.getGaizao_id());
                        params.put("token",token_data);
                        HttpUtils.requestPost(_mActivity, check_menph, params, new Request() {
                            @Override
                            public void success(String jsonStr) {
                                super.success(jsonStr);
                                LogUtils.i("校验门牌号", "getCheckMenPaihao: " + jsonStr);

                                MenPaiHaoEntity menPaiHaoEntity = GsonTools.changeGsonToBean(jsonStr, MenPaiHaoEntity.class);
                                if (menPaiHaoEntity != null) {
                                    if (1 == menPaiHaoEntity.getValid()) {
                                        showAlertOnlyPos(_mActivity, "门牌号不正确", "门牌号重复");
                                        cancelLoadingDialog();
                                        return;
                                    } else {
                                        fdIentity.setMenpaihao(menpaihao);
                                        BtSave();
                                    }
                                }
                                cancelLoadingDialog();
                            }

                            @Override
                            public void error(String error) {
                                super.error(error);
                                LogUtils.i("校验门牌号", "getCheckMenPaihao: " + error);
                                cancelLoadingDialog();
                            }
                        });
                    }
                } else {
                    //1.
                    //门牌号没有变化==还是请求下来的门牌号
                    fdIentity.setMenpaihao(menpaihao);
                    //正常校验
                    BtSave();
                }
                break;
        }
    }

    private void isEditableBuildStyle(String tv_statue) {

        if (!TextUtils.isEmpty(tv_statue)) {
            switch (tv_statue) {
                case "未改造":
                case "改造中":
                case "已改造":
                    acceptance_tv_stype.setEnabled(true);
                    break;

                case "旧有改造":
                    acceptance_tv_stype.setEnabled(false);
                    break;
            }

        }

    }


    /**
     * 跳转的图片展示页
     *
     * @param imageview
     * @param contextValue
     */
    private void GotoImageFg(ImageView imageview, String contextValue) {

        if (imageview.getVisibility() == View.VISIBLE && acceptImageEntities != null
                && acceptImageEntities.size() > 0) {
            for (AcceptImageEntity acceptiamgedata : acceptImageEntities) {
                String name = acceptiamgedata.getFile_des();
                String name1 = contextValue;
                if (contextValue.equals(acceptiamgedata.getFile_des())) {
                    EventBus.getDefault().post(new StartNewFragmentEvent(ImageShowFragment.newInstance(acceptiamgedata.getSys_file_name())));
                }

            }
        }

    }

    private void GotoImageFg(ImageView imageview, String contextValue, String value) {

        if (imageview.getVisibility() == View.VISIBLE && acceptImageEntities != null
                && acceptImageEntities.size() > 0) {
            for (AcceptImageEntity acceptiamgedata : acceptImageEntities) {
                if (contextValue.equals(acceptiamgedata.getFile_des()) || value.equals(acceptiamgedata.getFile_des())) {
                    EventBus.getDefault().post(new StartNewFragmentEvent(ImageShowFragment.newInstance(acceptiamgedata.getSys_file_name())));
                }

            }
        }

    }

    private List<AddNewShiGongTeamEntity> huafenchiEntityList;
    private List<AddNewShiGongTeamEntity> bainchiEntityList;
    private List<AddNewShiGongTeamEntity> shuichongEntityList;
    private List<AddNewShiGongTeamEntity> ceFangEntityList;

    /**
     * 获取厕房数据
     *
     * @param view
     */
    private void getCeFangType(final View view) {
        showLoadingDialog("厕房类型...");
        String the_last = HttpApis.addnew_cefang;
        LogUtils.i("厕房类型", "url: " + the_last);
        HashMap<String, String> map = new HashMap<>();
        map.put("token",token_data);
        HttpUtils.requestGet(_mActivity, the_last,map, new Request() {
            @Override
            public void success(String jsonStr) {
                super.success(jsonStr);

                LogUtils.i("厕房类型", "success: " + jsonStr);

                Type type = new TypeToken<ArrayList<AddNewShiGongTeamEntity>>() {
                }.getType();
                ceFangEntityList = JsonUtil.json2Collection(jsonStr, type);
                showCeFangPopu(view);
                cancelLoadingDialog();
            }

            @Override
            public void error(String error) {
                super.error(error);
                LogUtils.i("厕房类型", "error: " + error);
                cancelLoadingDialog();
            }
        });
    }

    /**
     * 加载厕房数据
     *
     * @param view
     */
    private void showCeFangPopu(View view) {
        beanShowList.clear();
        beanList.clear();
        beanIDList.clear();
        ListPopupWindow cefangPopupWindow = new ListPopupWindow(_mActivity);
        setCeFangPopuData(view, cefangPopupWindow, ceFangEntityList);
        setCeFangPopuClickListener(new CeFangPopuListener() {
            @Override
            public void show(List<AddNewShiGongTeamEntity> datalist) {
                beanList.clear();
                beanIDList.clear();
                for (AddNewShiGongTeamEntity rb : beanShowList) {
                    beanList.add(rb.getText());
                    beanIDList.add(rb.getValue());
                }

                String cefang_n = beanList.toString();// String str2 = str.replaceAll(" ", "");
//                cefang_n = cefang_n.replace("[", "");
//                cefang_n = cefang_n.replace("]", "");
//                cefang_n = cefang_n.replaceAll(" ", "");
                if(cefang_n.contains("[")){
                    cefang_n= StringUtil.deleteCharString(cefang_n,'[');
                }
                if(cefang_n.contains("]")){
                    cefang_n= StringUtil.deleteCharString(cefang_n,']');
                }
                if(cefang_n.contains(" ")){
                    cefang_n=StringUtil.deleteCharString(cefang_n,' ');
                }
                String cefang = beanIDList.toString();
//                cefang = cefang.replace("[", "");
//                cefang = cefang.replace("]", "");
//                cefang = cefang.replaceAll(" ", "");
                if(cefang.contains("[")){
                    cefang=StringUtil.deleteCharString(cefang,'[');
                }
                if(cefang.contains("]")){
                    cefang=StringUtil.deleteCharString(cefang,']');
                }
                if(cefang.contains(" ")){
                    cefang=StringUtil.deleteCharString(cefang,' ');
                }

                fileCefangTv.setText(cefang_n);

                fdIentity.setCefang_n(cefang_n);
                fdIentity.setCefang(cefang);

            }
        });

    }

    /**
     * 获取水冲方式数据
     *
     * @param view
     */
    private void getShuichongTYpe(final View view) {
        showLoadingDialog("水冲方式...");
        String the_last = HttpApis.addnew_chongshui;
        LogUtils.i("水冲方式", "url: " + the_last);
        HashMap<String, String> map = new HashMap<>();
        map.put("token",token_data);
        HttpUtils.requestGet(_mActivity, the_last,map, new Request() {
            @Override
            public void success(String jsonStr) {
                super.success(jsonStr);

                LogUtils.i("水冲方式", "success: " + jsonStr);

                Type type = new TypeToken<ArrayList<AddNewShiGongTeamEntity>>() {
                }.getType();


                shuichongEntityList = JsonUtil.json2Collection(jsonStr, type);

                showChongShuiPopu(view);

                cancelLoadingDialog();
            }

            @Override
            public void error(String error) {
                super.error(error);
                LogUtils.i("便池类型", "error: " + error);

                cancelLoadingDialog();
            }
        });
    }

    /**
     * 加载冲水数据
     *
     * @param view
     */
    private void showChongShuiPopu(View view) {
        ListPopupWindow chongshuiPopupWindow = new ListPopupWindow(_mActivity);
        setShigTeamPopuData(view, chongshuiPopupWindow, shuichongEntityList);
        setShigongTeamPopuClickListener(new AddNewShigTeamPopuListener() {
            @Override
            public void show(AddNewShiGongTeamEntity cetity, String mess) {
                fileChongshuiTv.setText(mess);

                fdIentity.setChongshuifangshi(cetity.getValue());
                fdIentity.setChongshuifangshi_n(cetity.getText());
            }
        });

    }

    /**
     * 获取便池的数据
     *
     * @param view
     */
    private void getBianchiType(final View view) {
        showLoadingDialog("便池类型...");
        String the_last = HttpApis.addnew_banchitype;
        LogUtils.i("便池类型", "url: " + the_last);
        HashMap<String, String> map = new HashMap<>();
        map.put("token",token_data);
        HttpUtils.requestGet(_mActivity, the_last,map, new Request() {
            @Override
            public void success(String jsonStr) {
                super.success(jsonStr);

                LogUtils.i("便池类型", "success: " + jsonStr);

                Type type = new TypeToken<ArrayList<AddNewShiGongTeamEntity>>() {
                }.getType();


                bainchiEntityList = JsonUtil.json2Collection(jsonStr, type);

                showBianchiPopu(view);

                cancelLoadingDialog();
            }

            @Override
            public void error(String error) {
                super.error(error);
                LogUtils.i("便池类型", "error: " + error);

                cancelLoadingDialog();
            }
        });
    }

    /**
     * 显示便池数据
     *
     * @param view
     */
    private void showBianchiPopu(View view) {
        ListPopupWindow bianchiPopupWindow = new ListPopupWindow(_mActivity);
        setShigTeamPopuData(view, bianchiPopupWindow, bainchiEntityList);
        setShigongTeamPopuClickListener(new AddNewShigTeamPopuListener() {
            @Override
            public void show(AddNewShiGongTeamEntity cetity, String mess) {
                fileBianchiTv.setText(mess);

                fdIentity.setBianchi(cetity.getValue());
                fdIentity.setBianchi_n(cetity.getText());
            }
        });
    }


    /**
     * 获取化粪池材料数据
     *
     * @param view
     */
    private void getHuaFenChiCailiao(final View view) {
        showLoadingDialog("化粪池材料...");
        String the_last = HttpApis.addnew_huafenchi;
        LogUtils.i("化粪池材料", "url: " + the_last);
        HashMap<String, String> map = new HashMap<>();
        map.put("token",token_data);
        HttpUtils.requestGet(_mActivity, the_last,map, new Request() {
            @Override
            public void success(String jsonStr) {
                super.success(jsonStr);

                LogUtils.i("化粪池材料", "success: " + jsonStr);

                Type type = new TypeToken<ArrayList<AddNewShiGongTeamEntity>>() {
                }.getType();


                huafenchiEntityList = JsonUtil.json2Collection(jsonStr, type);

                showHuaFenChiPopu(view);

                cancelLoadingDialog();
            }

            @Override
            public void error(String error) {
                super.error(error);
                LogUtils.i("化粪池材料", "error: " + error);

                cancelLoadingDialog();
            }
        });

    }

    /**
     * 化粪池材料PopupWindow
     *
     * @param view
     */
    private void showHuaFenChiPopu(View view) {
        ListPopupWindow huafenchiPopupWindow = new ListPopupWindow(_mActivity);
        setShigTeamPopuData(view, huafenchiPopupWindow, huafenchiEntityList);
        setShigongTeamPopuClickListener(new AddNewShigTeamPopuListener() {
            @Override
            public void show(AddNewShiGongTeamEntity cetity, String mess) {
                acceptance_tv_huaFeiChi.setText(mess);

                fdIentity.setHfc_material(cetity.getValue());
                fdIentity.setHfc_material_n(cetity.getText());

            }
        });

    }


    /**
     * 提交数据
     */
    private void BtSave() {
        //检查各个字段的值
        boolean isCheck = CheckFildValue();
        if (!isCheck) {
            cancelLoadingDialog();
            return;
        }
//        String build_state = acceptanceTvBuildstate.getText().toString().trim();
//        if (TextUtils.isEmpty(build_state) || "旧有改造".equals(build_state)) {
//            showShortToast("旧有改造状态不能保存");
//            return;
//        } else {
//            savecommit();
//        }

        savecommit();
    }

    /**
     * 根据状态显示要上传的值
     */
    private void UpShowForState(String tv_statue) {
        if (!TextUtils.isEmpty(tv_statue)) {
            switch (tv_statue) {
                case "未改造":

                    upAllIdpic.setVisibility(View.VISIBLE);
                    upAllBefore.setVisibility(View.VISIBLE);
                    upAllIng.setVisibility(View.VISIBLE);
                    upAllDanganGaizaotwo.setVisibility(View.VISIBLE);
                    upAllDanganGaizaothree.setVisibility(View.VISIBLE);

                    break;
                case "改造中":


//                    acceptanceTvBuildtype.setVisibility(View.VISIBLE);
//                    acceptanceTvTeamname.setVisibility(View.VISIBLE);
//                    acceptance_tv_huaFeiChi.setVisibility(View.VISIBLE);
//
//                    fileBianchiTv.setVisibility(View.VISIBLE);
//                    fileChongshuiTv.setVisibility(View.VISIBLE);
//                    fileCefangTv.setVisibility(View.VISIBLE);
                    upAllIdpic.setVisibility(View.VISIBLE);
                    upAllBefore.setVisibility(View.VISIBLE);
                    upAllIng.setVisibility(View.VISIBLE);
                    upAllDanganGaizaotwo.setVisibility(View.VISIBLE);
                    upAllDanganGaizaothree.setVisibility(View.VISIBLE);
                    break;

                case "已改造":




                    String update_count = fileDetialEntity.getUpdate_count();
                    String gz_update_count = fileDetialEntity.getGz_update_count();
                    /*已改造去掉次数限制*/
                    if(!TextUtils.isEmpty(gz_update_count)){
                        fdIentity.setUpdate_count(gz_update_count);//用于提交
                        int upCount = Integer.parseInt(gz_update_count);
                        if(upCount>=3){
//                            acceptanceBtSave.setEnabled(false);
//                            acceptanceBtSave.setClickable(false);
//                            acceptanceBtSave.setBackgroundResource(R.drawable.toilet_sliding_tv_unselected);
                        }
                    }


//                    acceptanceTvBuildtype.setVisibility(View.VISIBLE);
//                    acceptanceTvTeamname.setVisibility(View.VISIBLE);
//                    acceptance_tv_huaFeiChi.setVisibility(View.VISIBLE);
//
//                    fileBianchiTv.setVisibility(View.VISIBLE);
//                    fileChongshuiTv.setVisibility(View.VISIBLE);
//                    fileCefangTv.setVisibility(View.VISIBLE);
                    upAllIdpic.setVisibility(View.VISIBLE);
                    upAllBefore.setVisibility(View.VISIBLE);
                    upAllIng.setVisibility(View.VISIBLE);
                    upAllDanganGaizaotwo.setVisibility(View.VISIBLE);
                    upAllDanganGaizaothree.setVisibility(View.VISIBLE);
                    break;

                case "旧有改造":



                    acceptanceEtAddress.setEnabled(false);
                    //门牌号
                    acceptanceEtDoorcode.setEnabled(false);
                    //户名
                    acceptanceEtDoorname.setEnabled(false);
                    //家庭人口
                    etHunmanNumbers.setEnabled(false);
                    //联系电话
                    etFileTel.setEnabled(false);
                    //户编号
                    acceptanceEtDoornumberning.setEnabled(false);
                    //身份证号
                    acceptanceEtIdnumber.setEnabled(false);
                    //是否闲置
                    acceptanceTvIsIdel.setEnabled(false);
                    //改造状态
                    acceptanceTvBuildstate.setEnabled(false);
                    //任务年份
                    //acceptanceTvBuildyear.setEnabled(false);
                    //改造类型
                    acceptanceTvBuildtype.setEnabled(false);
                    //改厕方式
                    acceptance_tv_stype.setEnabled(false);
                    //施工队伍名称
                    acceptanceTvTeamname.setEnabled(false);
                    //化粪池材料
                    acceptance_tv_huaFeiChi.setEnabled(false);
                    //便池类型
                    fileBianchiTv.setEnabled(false);
                    //冲水方式
                    fileChongshuiTv.setEnabled(false);
                    //厕房类型
                    fileCefangTv.setEnabled(false);

                    upAllIdpic.setVisibility(View.VISIBLE);
                    upAllBefore.setVisibility(View.VISIBLE);
                    upAllIng.setVisibility(View.VISIBLE);
                    upAllDanganGaizaotwo.setVisibility(View.VISIBLE);
                    upAllDanganGaizaothree.setVisibility(View.VISIBLE);

                    acceptanceBtSave.setEnabled(true);
                    acceptanceBtSave.setClickable(true);
                    //acceptanceBtSave.setBackgroundResource(R.drawable.toilet_sliding_tv_unselected);
                        break;

                default:
//                    acceptanceTvBuildtype.setVisibility(View.VISIBLE);
//                    acceptanceTvTeamname.setVisibility(View.VISIBLE);
//                    acceptance_tv_huaFeiChi.setVisibility(View.VISIBLE);
                    break;
            }
        }
    }

    /**
     * 根据改造状态获取改造类型
     */
    private void getStateType(View view) {
        String state_build = acceptanceTvBuildstate.getText().toString().trim();
        if (TextUtils.isEmpty(state_build) || state_build == null) {
            Toast.makeText(_mActivity, "请先选择改造状态", Toast.LENGTH_SHORT).show();
            return;
        }
        switch (state_build) {
            case "已改造":
            case "未改造":
            case "改造中":
                //getFontTypeData(view);
                getLastTypeData(view);
                break;
            case "旧有改造":
                getLastTypeData(view);
                //getFontTypeData(view);
                break;
            default:
                break;
        }


    }

    /**
     * 获取前三种改造状态对应的改造类型
     */
    private void getFontTypeData(final View view) {

        showLoadingDialog("改造类型...");
        String the_threeurl = HttpApis.addnew_fontThree;
        LogUtils.i("前三个状态", "url: " + the_threeurl);
        HashMap<String, String> map = new HashMap<>();
        map.put("token",token_data);
        HttpUtils.requestGet(_mActivity, the_threeurl,map, new Request() {
            @Override
            public void success(String jsonStr) {
                super.success(jsonStr);
                LogUtils.i("前三个状态", "success: " + jsonStr);
                Type type = new TypeToken<ArrayList<AddNewBuildTypeEntity>>() {
                }.getType();
                addNewBuildTypeEntityList = JsonUtil.json2Collection(jsonStr, type);
                showBuildTypePopu(view);
                cancelLoadingDialog();
            }

            @Override
            public void error(String error) {
                super.error(error);
                LogUtils.i("前三个状态", "error: " + error);
                cancelLoadingDialog();
            }
        });

    }


    /**
     * 获取第四种改造状态对应的改造类型
     */
    private void getLastTypeData(final View view) {
        showLoadingDialog("改造类型...");
        String the_last = HttpApis.addnew_last;
        LogUtils.i("第四个状态", "url: " + the_last);
        HashMap<String, String> map = new HashMap<>();
        map.put("token",token_data);
        HttpUtils.requestGet(_mActivity, the_last,map, new Request() {
            @Override
            public void success(String jsonStr) {
                super.success(jsonStr);
                LogUtils.i("第四个状态", "success: " + jsonStr);
                Type type = new TypeToken<ArrayList<AddNewBuildTypeEntity>>() {
                }.getType();
                addNewBuildTypeEntityList = JsonUtil.json2Collection(jsonStr, type);
                showBuildTypePopu(view);
                cancelLoadingDialog();
            }

            @Override
            public void error(String error) {
                super.error(error);
                LogUtils.i("第四个状态", "error: " + error);
                cancelLoadingDialog();
            }
        });
    }

    /**
     * 显示改造类型popuwindow
     *
     * @param view
     */
    private void showBuildTypePopu(View view) {

        addnewtypelist.clear();
        beanTypeList.clear();
        beanTypeIDList.clear();

        buildtypePopupWindow = new ListPopupWindow(_mActivity);
        setbuildTypePopuData(view, buildtypePopupWindow, addNewBuildTypeEntityList);
//        setbuildTypePopuClickListener(new AddNewBuildTypePopuListener() {
//            @Override
//            public void show(AddNewBuildTypeEntity cetity, String mess) {
//                acceptanceTvBuildtype.setText(mess);
//                if (saveparams.containsKey("gaizao_type_n")) {
//                    saveparams.remove("gaizao_type_n");
//                }
//                if (saveparams.containsKey("gaizao_type")) {
//                    saveparams.remove("gaizao_type");
//                }
//
//                fdIentity.setGaizao_type(cetity.getValue());
//                fdIentity.setGaizao_type_n(cetity.getText());
//            }
//        });
        setbuildTypePopuClickListener(new BuildTypePopuListener() {
            @Override
            public void show(List<AddNewBuildTypeEntity> datalist) {
                beanTypeList.clear();
                beanTypeIDList.clear();

                for (AddNewBuildTypeEntity abte : addnewtypelist) {
                    //beanTypeList.add(abte.getText());
                    beanTypeIDList.add(abte.getValue());
                }

                Collections.sort(beanTypeIDList);

                for (String idValue: beanTypeIDList) {
                    if("201".equals(idValue)){
                        beanTypeList.add("厕屋");
                    }
                    if("202".equals(idValue)){
                        beanTypeList.add("便器");
                    }
                    if("203".equals(idValue)){
                        beanTypeList.add("化粪池");
                    }
                }

                String buildtype_n = beanTypeList.toString();
                if(buildtype_n.contains("[")){
                    buildtype_n= StringUtil.deleteCharString(buildtype_n,'[');
                }
                if(buildtype_n.contains("]")){
                    buildtype_n= StringUtil.deleteCharString(buildtype_n,']');
                }
                if(buildtype_n.contains(" ")){
                    buildtype_n=StringUtil.deleteCharString(buildtype_n,' ');
                }
                String buildtype_Id = beanTypeIDList.toString();
                if(buildtype_Id.contains("[")){
                    buildtype_Id=StringUtil.deleteCharString(buildtype_Id,'[');
                }
                if(buildtype_Id.contains("]")){
                    buildtype_Id=StringUtil.deleteCharString(buildtype_Id,']');
                }
                if(buildtype_Id.contains(" ")){
                    buildtype_Id=StringUtil.deleteCharString(buildtype_Id,' ');
                }

                acceptanceTvBuildtype.setText(buildtype_n);

                fdIentity.setGaizao_type_n(buildtype_n);
                fdIentity.setGaizao_type(buildtype_Id);
            }
        });
    }

    /**
     * 获取施工队数据
     *
     * @param village_value
     */
    private void getShigongTeamData(final View view, String village_value) {
        showLoadingDialog("施工队伍...");
        LogUtils.i("施工队", "getShigongTeamData: " + village_value);

        //设置假的施工队数据
        String shigongteamUrl = HttpApis.addnew_teamdata + village_value;
        LogUtils.i("施工队", "url: " + shigongteamUrl);
        HashMap<String, String> map = new HashMap<>();
        map.put("token",token_data);
        HttpUtils.requestGet(_mActivity, shigongteamUrl,map, new Request() {
            @Override
            public void success(String jsonStr) {
                super.success(jsonStr);

                LogUtils.i("施工队", "success: " + jsonStr);

                Type type = new TypeToken<ArrayList<AddNewShiGongTeamEntity>>() {
                }.getType();

                addNewShigongteamEntityList = JsonUtil.json2Collection(jsonStr, type);
                showShigongTeamPopu(view);
                cancelLoadingDialog();
            }

            @Override
            public void error(String error) {
                super.error(error);
                LogUtils.i("施工队", "error: " + error);
                cancelLoadingDialog();
            }
        });

    }

    /**
     * 显示施工队popuwindow
     *
     * @param view
     */
    private void showShigongTeamPopu(View view) {
        TeamNamePopupWindow = new ListPopupWindow(_mActivity);
        setShigTeamPopuData(view, TeamNamePopupWindow, addNewShigongteamEntityList);
        setShigongTeamPopuClickListener(new AddNewShigTeamPopuListener() {
            @Override
            public void show(AddNewShiGongTeamEntity cetity, String mess) {
                acceptanceTvTeamname.setText(mess);
                fdIentity.setShgd_id(cetity.getValue());
                fdIentity.setShgd_name(cetity.getText());
            }
        });
    }

    private int rosterIndex = 0;
    private List<AddNewShiGongTeamEntity> beanShowList = new ArrayList<>();
    private List<String> beanList = new ArrayList<>();
    private List<String> beanIDList = new ArrayList<>();
    private List<AddNewShiGongTeamEntity> mRosterList = new ArrayList<>();

    private void setCeFangPopuData(View view, final ListPopupWindow mPopupWindow, final List<AddNewShiGongTeamEntity> datalist) {
        myAdapter = new CeFangAdapter(_mActivity, datalist);
        mPopupWindow.setAdapter(myAdapter);
        //弹出的位置  弹出锚点
        mPopupWindow.setAnchorView(view);
        mPopupWindow.setVerticalOffset(ConvertUtils.dp2px(_mActivity, 16));
        //设置宽高
        mPopupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        mPopupWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
        mPopupWindow.setModal(true);//设置模态框，设置为true响应物理键
        mPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                for (AddNewShiGongTeamEntity rb : beanShowList) {
                    beanList.add(rb.getText());
                    beanIDList.add(rb.getValue());
                }
                //除重后添加
                String cefang_n = removeRepeat(beanList).toString();
//                cefang_n = cefang_n.replace("[", "");
//                cefang_n = cefang_n.replace("]", "");
//                cefang_n = cefang_n.replaceAll(" ", "");
                if(cefang_n.contains("[")){
                    cefang_n= StringUtil.deleteCharString(cefang_n,'[');
                }
                if(cefang_n.contains("]")){
                    cefang_n= StringUtil.deleteCharString(cefang_n,']');
                }
                if(cefang_n.contains(" ")){
                    cefang_n=StringUtil.deleteCharString(cefang_n,' ');
                }
                String cefang = removeRepeat(beanIDList).toString();
//                cefang = cefang.replace("[", "");
//                cefang = cefang.replace("]", "");
//                cefang = cefang.replaceAll(" ", "");
                if(cefang.contains("[")){
                    cefang=StringUtil.deleteCharString(cefang,'[');
                }
                if(cefang.contains("]")){
                    cefang=StringUtil.deleteCharString(cefang,']');
                }
                if(cefang.contains(" ")){
                    cefang=StringUtil.deleteCharString(cefang,' ');
                }
                fdIentity.setCefang_n(cefang_n);
                fdIentity.setCefang(cefang);
                LogUtils.i("厕房显示", "内容: " + fdIentity.getCefang_n());
                LogUtils.i("厕房显示", "ID: " + fdIentity.getCefang());
                beanList.clear();
                beanIDList.clear();
            }
        });

        //设置条目点击事件
        mPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                if (datalist.get(position).isSelected() == false) {
                    rosterIndex++;
                    beanShowList.add(datalist.get(position));
                    datalist.get(position).setSelected(true);
                } else {
                    rosterIndex--;
                    if (beanShowList.contains(datalist.get(position))) {
                        beanShowList.remove(datalist.get(position));
                    }
                    datalist.get(position).setSelected(false);
                }
                if (rosterIndex == 0) {
                    fileCefangTv.setText("");
                    beanShowList.clear();
                    mPopupWindow.dismiss();
                } else {
                    //使用回调,显示数据
                    if (cefangPopuListener != null) {
                        cefangPopuListener.show(beanShowList);
                    }
                }

                myAdapter.notifyDataSetChanged();
            }
        });
        mPopupWindow.show();
    }


    public CeFangPopuListener cefangPopuListener;

    public void setCeFangPopuClickListener(CeFangPopuListener cefangPopuListener) {
        this.cefangPopuListener = cefangPopuListener;
    }


    private List<String> removeRepeat(List<String> list) {
        List<String> no_list = new ArrayList<>();
        for (String show_str : list) {
            if (!no_list.contains(show_str)) {
                no_list.add(show_str);
            }
        }
        return no_list;
    }

    private List<String> addnewshigtlist = new ArrayList<>();

    private void setShigTeamPopuData(View view, final ListPopupWindow mPopupWindow, final List<AddNewShiGongTeamEntity> datalist) {
        addnewshigtlist.clear();
        for (AddNewShiGongTeamEntity abte : datalist) {
            addnewshigtlist.add(abte.getText());
        }

        ArrayAdapter<String> adapter = new ArrayAdapter<>(_mActivity, android.R.layout.simple_list_item_1, addnewshigtlist);
        mPopupWindow.setAdapter(adapter);

        //弹出的位置  弹出锚点
        mPopupWindow.setAnchorView(view);
        //设置宽高
        mPopupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        mPopupWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);

        mPopupWindow.setModal(true);//设置模态框，设置为true响应物理键
        //设置条目点击事件
        mPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                //使用回调,显示数据
                if (anshigongteamClickListener != null) {
                    anshigongteamClickListener.show(datalist.get(position), addnewshigtlist.get(position));
                }
                mPopupWindow.dismiss();
            }
        });
        mPopupWindow.show();
    }

    public AddNewShigTeamPopuListener anshigongteamClickListener;

    public void setShigongTeamPopuClickListener(AddNewShigTeamPopuListener anshigongteamClickListener) {
        this.anshigongteamClickListener = anshigongteamClickListener;
    }

    private List<AddNewBuildTypeEntity> addnewtypelist = new ArrayList<>();
    private int buildtypeIndex = 0;
    private List<String> beanTypeList = new ArrayList<>();
    private List<String> beanTypeIDList = new ArrayList<>();

    private void setbuildTypePopuData(View view, final ListPopupWindow mPopupWindow, final List<AddNewBuildTypeEntity> datalist) {

//        addnewtypelist.clear();
//        for (AddNewBuildTypeEntity abte : datalist) {
//            addnewtypelist.add(abte.getText());
//        }

        myBuildTypeAdapter = new GaizaoTypeAdapter(_mActivity, datalist);
        mPopupWindow.setAdapter(myBuildTypeAdapter);

        mPopupWindow.setVerticalOffset(ConvertUtils.dp2px(_mActivity, 16));


        //弹出的位置  弹出锚点
        mPopupWindow.setAnchorView(view);
        //设置宽高
        mPopupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        mPopupWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);

        mPopupWindow.setModal(true);//设置模态框，设置为true响应物理键


        mPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {

                for (AddNewBuildTypeEntity rb : addnewtypelist) {
                    beanTypeList.add(rb.getText());
                    beanTypeIDList.add(rb.getValue());
                }


                String buildtype_n = removeRepeat(beanTypeList).toString();
                if(buildtype_n.contains("[")){
                    buildtype_n= StringUtil.deleteCharString(buildtype_n,'[');
                }
                if(buildtype_n.contains("]")){
                    buildtype_n= StringUtil.deleteCharString(buildtype_n,']');
                }
                if(buildtype_n.contains(" ")){
                    buildtype_n=StringUtil.deleteCharString(buildtype_n,' ');
                }


                String beanType_id = removeRepeat(beanTypeIDList).toString();
                if(beanType_id.contains("[")){
                    beanType_id=StringUtil.deleteCharString(beanType_id,'[');
                }
                if(beanType_id.contains("]")){
                    beanType_id=StringUtil.deleteCharString(beanType_id,']');
                }
                if(beanType_id.contains(" ")){
                    beanType_id=StringUtil.deleteCharString(beanType_id,' ');
                }


                if(TextUtils.isEmpty(acceptanceTvBuildtype.getText().toString().trim())){

                    fdIentity.setGaizao_type("");
                    fdIentity.setGaizao_type_n("");
                }

//                fdIentity.setGaizao_type(beanType_id);
//                fdIentity.setGaizao_type_n(buildtype_n);


                Log.i("改造类型显示", "内容: " + fdIentity.getGaizao_type_n());
                Log.i("改造类型显示", "ID: " + fdIentity.getGaizao_type());


                beanTypeList.clear();
                beanTypeIDList.clear();
            }
        });


        //设置条目点击事件
        mPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                //使用回调,显示数据

                if (datalist.get(position).isSelected() == false) {
                    buildtypeIndex++;
                    addnewtypelist.add(datalist.get(position));
                    datalist.get(position).setSelected(true);
                } else {
                    buildtypeIndex--;
                    if (addnewtypelist.contains(datalist.get(position))) {
                        addnewtypelist.remove(datalist.get(position));
                    }
                    datalist.get(position).setSelected(false);
                }
                if (buildtypeIndex == 0) {
                    acceptanceTvBuildtype.setText("");
                    addnewtypelist.clear();
                    mPopupWindow.dismiss();
                } else {
                    //使用回调,显示数据
                    if (buildTypePopuListener != null) {
                        buildTypePopuListener.show(addnewtypelist);
                    }
                }

                myBuildTypeAdapter.notifyDataSetChanged();
            }
        });
        mPopupWindow.show();
    }

    public BuildTypePopuListener buildTypePopuListener;

    public void setbuildTypePopuClickListener(BuildTypePopuListener buildTypePopuListener) {
        this.buildTypePopuListener = buildTypePopuListener;
    }
//    public AddNewBuildTypePopuListener anbtbtClickListener;
//
//    public void setbuildTypePopuClickListener(AddNewBuildTypePopuListener popudefaultClickListener) {
//        this.anbtbtClickListener = popudefaultClickListener;
//    }

    private Map<String, String> saveparams = new TreeMap<>();

    private boolean CheckFildValue() {
        //改造状态 addNewTvBuildstate
        String build_state = acceptanceTvBuildstate.getText().toString().trim();
        if (TextUtils.isEmpty(build_state)) {
            //Toast.makeText(_mActivity, "请选择改造状态", Toast.LENGTH_SHORT).show();
            showAlertOnlyPos(_mActivity, "", "请选择改造状态");
            return false;
        } else {
            fdIentity.setGaizao_state_n(build_state);
            switch (build_state) {
                case "已改造":
                    fdIentity.setGaizao_state("403");
                    break;
                case "改造中":
                    fdIentity.setGaizao_state("402");
                    break;
                case "未改造":
                    fdIentity.setGaizao_state("401");
                    break;
                case "旧有改造":
                    fdIentity.setGaizao_state("404");
                    break;

                default:

                    break;
            }

            String old_statue_ = SPUtil.getString(Constants.OLD_GAIZAO_STATE, "");
            if(!TextUtils.isEmpty(old_statue_)){
                fdIentity.setOld_gaizao_state(SPUtil.getString(Constants.OLD_GAIZAO_STATE,""));
            }

        }
        //户名
        String huming = acceptanceEtDoorname.getText().toString().trim();

        if(TextUtils.isEmpty(huming)){
            showAlertOnlyPos(_mActivity, "户名", "请输入户名");
            return false;
        }


        if (!huming.matches("[\u4e00-\u9fa5]+")) {
            //if ("已改造".equals(build_state)) {
                //Toast.makeText(_mActivity, "户名格式请输入汉字", Toast.LENGTH_SHORT).show();
                showAlertOnlyPos(_mActivity, "户名", "户名格式请输入汉字");
                return false;
            //}
        }
        //校验过后,在添加
        fdIentity.setHuming(huming);
        //家庭人口
        String humans = etHunmanNumbers.getText().toString().trim();
        fdIentity.setRenkou(humans);
        if (!TextUtils.isEmpty(humans)) {
            int human_num = Integer.parseInt(humans);
            if (human_num <= 0 || human_num >= 100) {
                //showShortToast("请输入1~100以内整数");
                showAlertOnlyPos(_mActivity, "", "请输入1~100以内整数");
                return false;
            } else {
                fdIentity.setRenkou(humans);
            }

        }
        //联系电话
        String human_tel = etFileTel.getText().toString().trim();
        if(!TextUtils.isEmpty(human_tel)){
            if(!RegexUtils.isMobileExact(human_tel)){
                showAlertOnlyPos(_mActivity, "联系电话", "联系电话格式不正确");
                return false;
            }
        }
        fdIentity.setPhone(human_tel);
        //户编号
        String hubianhao = acceptanceEtDoornumberning.getText().toString().trim();
        fdIentity.setHubianhao(hubianhao);
        //身份证号
        String cert_no = acceptanceEtIdnumber.getText().toString().trim();
        if (!TextUtils.isEmpty(cert_no) && RegexUtils.isIDCard18(cert_no)) {
            fdIentity.setCert_no_sec(cert_no);
        } else {
            if(TextUtils.isEmpty(cert_no)){
                showAlertOnlyPos(_mActivity, "身份证号", "请输入身份证号");
            }else{
                showAlertOnlyPos(_mActivity, "身份证号", "身份证号格式错误");
            }
            return false;
        }
        if ("已改造".equals(build_state)) {
            if (TextUtils.isEmpty(cert_no) || !RegexUtils.isIDCard18(cert_no)) {
                showAlertOnlyPos(_mActivity, "身份证号", "请输入身份证号");
                return false;
            }
        }


        //是否闲置
        String isIdle = acceptanceTvIsIdel.getText().toString().trim();
        if (TextUtils.isEmpty(isIdle)) {
        } else {
            if ("是".equals(isIdle)) {
                fdIentity.setXianzhi("1");
                fdIentity.setXianzhi_n("是");
                acceptance_tv_stype.setEnabled(false);
            } else if ("否".equals(isIdle)) {
                fdIentity.setXianzhi("0");
                fdIentity.setXianzhi_n("否");
            }

        }
        //任务年份 和改造状态有关
        String build_states = acceptanceTvBuildstate.getText().toString().trim();
        String buildyear = acceptanceTvBuildyear.getText().toString().trim();
        if ("已改造".equals(build_states) || "改造中".equals(build_states) || "未改造".equals(build_states)) {
            if (TextUtils.isEmpty(buildyear)) {
                showAlertOnlyPos(_mActivity, "任务年份", "请选择任务年份");
                cancelLoadingDialog();
                return false;
            } else {

                if("2020年之前".equals(buildyear)){
                    fdIentity.setStat_year("2019");
                }else if("2020年".equals(buildyear)){
                    fdIentity.setStat_year("2020");
                }
                fdIentity.setStat_year_n(buildyear);

                //fdIentity.setStat_year(buildyear);
            }

        } else {
            if("2020年之前".equals(buildyear)){
                fdIentity.setStat_year("2019");
            }else if("2020年".equals(buildyear)){
                fdIentity.setStat_year("2020");
            }else if(TextUtils.isEmpty(buildyear)){
                fdIentity.setStat_year("");
            }
            fdIentity.setStat_year(buildyear);
        }
        if ("否".equals(isIdle)) {
            switch (build_states) {
                case "已改造":
                    //改造类型
                    String build_type_names = acceptanceTvBuildtype.getText().toString().trim();
                    if (TextUtils.isEmpty(build_type_names)) {
                        showAlertOnlyPos(_mActivity, "改造类型", "请选择改造类型");
                        return false;
                    }

                    //化粪池材料
//                    String huafcMs = acceptance_tv_huaFeiChi.getText().toString().trim();
//                    if (TextUtils.isEmpty(huafcMs)) {
//                        showAlertOnlyPos(_mActivity, "化粪池材料", "请选输入化粪池材料");
//                        return false;
//                    }
//                    //冲水方式
//                    String chongshuitype = fileChongshuiTv.getText().toString().trim();
//                    if (TextUtils.isEmpty(chongshuitype)) {
//                        showAlertOnlyPos(_mActivity, "冲水方式", "请输入冲水方式");
//                        return false;
//                    }
                    //身份证正面、大门照、改造前、改造中、改造后
                    if (!isImageAfSuccess || !isImageDoorFontSuccess) {//!isImageMidSuccess || !isImageAfSuccess ||!isImageIdSuccess || !isImageDoorFontSuccess || !isImageBfSuccess
                        showAlertOnlyPos(_mActivity, "照片", "请上传大门照片和改造后照片");
                        cancelLoadingDialog();
                        return false;
                    }
                    //改造中2，改造中3为必填项
//                    if (!isImageingTwoSuccess || !isImageingThreeSuccess) {//!isImageMidSuccess || !isImageAfSuccess ||!isImageIdSuccess || !isImageDoorFontSuccess || !isImageBfSuccess
//                        showAlertOnlyPos(_mActivity, "照片", "请上传改造中2照片和改造中3照片");
//                        cancelLoadingDialog();
//                        return false;
//                    }
                    //当改造类型为沼气池改良式、通风改良+粪便集中无害化式两种时，改造中1为非必填，当改造类型为其他7种时，改造中1为必填。
                    if("沼气池改良式".equals(build_type_names)||"通风改良+粪便集中无害化式".equals(build_type_names)){

                    }else{
//                        if (!isImageMidSuccess ) {//!isImageMidSuccess || !isImageAfSuccess ||!isImageIdSuccess || !isImageDoorFontSuccess || !isImageBfSuccess
//                            showAlertOnlyPos(_mActivity, "照片", "请上传改造中1照片");
//                            cancelLoadingDialog();
//                            return false;
//                        }
                    }


                    break;
                case "改造中":
                    //改造中 必填项：改造类型、施工队名称、化粪池材料、身份证正面、大门照、改造前、改造中
                    //改造类型
                    String build_type_name = acceptanceTvBuildtype.getText().toString().trim();
                    if (TextUtils.isEmpty(build_type_name)) {
                        showAlertOnlyPos(_mActivity,"改造类型","请输入改造类型");
                        return false;
                    }
                    //施工队名称
                    String shigteamname = acceptanceTvTeamname.getText().toString().trim();
                    if (TextUtils.isEmpty(shigteamname)) {
                        showAlertOnlyPos(_mActivity,"施工队伍","请选择施工队伍");
                        return false;
                    }
                    //化粪池材料
//                    String huafcM = acceptance_tv_huaFeiChi.getText().toString().trim();
//                    if (TextUtils.isEmpty(huafcM)) {
//                        showAlertOnlyPos(_mActivity,"化粪池材料","请输入化粪池材料");
//                        return false;
//                    }

                    //身份证正面、大门照、改造前、改造中
//                    if (!isImageMidSuccess || !isImageAfSuccess || !isImageIdSuccess || !isImageDoorFontSuccess) {
//                        //showShortToast("请上传身份证正面照片,大门前照片,改造前照片和改造中照片");
//                        showAlertOnlyPos(_mActivity,"照片","请上传身份证正面照片,大门前照片,改造前照片和改造中照片");
//                        cancelLoadingDialog();
//                        return false;
//                    }
                    //大门照、改造中
                    if (!isImageDoorFontSuccess) {
                        showAlertOnlyPos(_mActivity,"照片","请上传大门前照片");
                        cancelLoadingDialog();
                        return false;
                    }
                    break;
                case "未改造":
                    break;
                case "旧有改造":
                    //必填 改造类型    保存之后，编辑时只可修改大门照、改造后照片
                    //acceptanceTvBuildyear
                    //改造类型
//                    String build_type_name_jiu = acceptanceTvBuildtype.getText().toString().trim();
//                    if (TextUtils.isEmpty(build_type_name_jiu)) {
//                        showAlertOnlyPos(_mActivity, "改造类型", "请选择改造类型");
//                        return false;
//                    }
//                    String build_year = acceptanceTvBuildyear.getText().toString().trim();
//                    if (TextUtils.isEmpty(build_year)) {
//                        showAlertOnlyPos(_mActivity, "任务年份", "请选择任务年份");
//                        return false;
//                    }



                    break;

                default:

                    break;
            }
        }

        //build_state
        String build_type_names1 = acceptanceTvBuildtype.getText().toString().trim();
        if ("改造中".equals(build_states) || "未改造".equals(build_states)) {
            if ("外建公厕".equals(build_type_names1)) {
                showAlertOnlyPos(_mActivity, "改造类型", "未改造或改造中不可外建公厕");
                return false;
            }

        }

        //改厕放式   isIdle  是否闲置为是，非必填。
        //是否闲置为否，改造状态为未改造、旧有改造，非必填。
        //是否闲置为否，改造状态为改造中、已改造，必填。
        if ("否".equals(isIdle)) {
            String build_style = acceptance_tv_stype.getText().toString();
            if ("改造中".equals(build_states) || "已改造".equals(build_states)) {
                if(TextUtils.isEmpty(build_style)){
                    showAlertOnlyPos(_mActivity, "改厕方式", "请选择改厕方式");
                    return false;
                }

//                else{
//                    if ("农户自改自建".equals(build_style)) {
//                        fdIentity.setGaizao_fangshi("1001");
//                        fdIentity.setGaizao_fangshi_n("农户自改自建");
//                    } else if ("政府主导统一施工".equals(build_style)) {
//                        fdIentity.setGaizao_fangshi("1002");
//                        fdIentity.setGaizao_fangshi_n("政府主导统一施工");
//                    }
//                }

            }

            if ("农户自改自建".equals(build_style)) {
                fdIentity.setGaizao_fangshi("1001");
                fdIentity.setGaizao_fangshi_n("农户自改自建");
            } else if ("政府主导统一施工".equals(build_style)) {
                fdIentity.setGaizao_fangshi("1002");
                fdIentity.setGaizao_fangshi_n("政府主导统一施工");
            }
        }

//        if ("否".equals(isIdle)) {
//            if ("改造中".equals(build_states) || "已改造".equals(build_states)) {
//                String build_style = acceptance_tv_stype.getText().toString();
//                if ("农户自改自建".equals(build_style)) {
//                    fdIentity.setGaizao_fangshi("1001");
//                    fdIentity.setGaizao_fangshi_n("农户自改自建");
//                } else if ("政府主导统一施工".equals(build_style)) {
//                    fdIentity.setGaizao_fangshi("1002");
//                    fdIentity.setGaizao_fangshi_n("政府主导统一施工");
//                }
//
//            }
//        }


        //化肥池材料
        String huafcM = acceptance_tv_huaFeiChi.getText().toString().trim();
        fdIentity.setHfc_material_n(huafcM);
        return true;

    }

    /**
     * 得到当前时间
     */
    private String getNowTime() {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
        Date curDate = new Date(System.currentTimeMillis());//获取当前时间
        String str = formatter.format(curDate);
        return str;
    }

    /**
     * 点击按钮,提交
     */
    private void savecommit() {
        String savecommitUrl = HttpApis.file_detile_update_head
                + getdataBean.getGaizao_id();
        showLoadingDialog();

        //后来补加
        fdIentity.setIdfield("gaizao_id");
        //fdIentity.setState_id("dengji");

        fdIentity.setToken(token_data);

        if (commitRequest == null) {
            commitRequest = new CommitRequest();
        }


        fdIentity.setBuchongfu(getNowTime() + "");
        String[] arr_adjunct_id = new String[]{before_ima[0], ing_ima[0], after_ima[0], idcard_ima[0], fodoor_ima[0],ing_ima_two[0],ing_ima_three[0]};

        arr_adjunct_id = arrayRemoveSpace(arr_adjunct_id);

        String[] arr_sys_file_name = new String[]{before_ima[1], ing_ima[1], after_ima[1], idcard_ima[1], fodoor_ima[1],ing_ima_two[1],ing_ima_three[1]};
        arr_sys_file_name = arrayRemoveSpace(arr_sys_file_name);

        String[] arr_adjunct_type = new String[]{before_ima[2], ing_ima[2], after_ima[2], idcard_ima[2], fodoor_ima[2],ing_ima_two[2],ing_ima_three[2]};
        arr_adjunct_type = arrayRemoveSpace(arr_adjunct_type);

        String[] arr_file_type = new String[]{before_ima[3], ing_ima[3], after_ima[3], idcard_ima[3], fodoor_ima[3],ing_ima_two[3],ing_ima_three[3]};
        arr_file_type = arrayRemoveSpace(arr_file_type);

        String[] arr_file_size = new String[]{before_ima[4], ing_ima[4], after_ima[4], idcard_ima[4], fodoor_ima[4],ing_ima_two[4],ing_ima_three[4]};
        arr_file_size = arrayRemoveSpace(arr_file_size);

        String[] arr_file_des = new String[]{before_ima[5], ing_ima[5], after_ima[5], idcard_ima[5], fodoor_ima[5],ing_ima_two[5],ing_ima_three[5]};
        arr_file_des = arrayRemoveSpace(arr_file_des);

        String[] arr_user_file_name = new String[]{before_ima[6], ing_ima[6], after_ima[6], idcard_ima[6], fodoor_ima[6],ing_ima_two[6],ing_ima_three[6]};
        arr_user_file_name = arrayRemoveSpace(arr_user_file_name);

        String[] arr_picmd5code = new String[]{before_ima[7], ing_ima[7], after_ima[7], idcard_ima[7], fodoor_ima[7],ing_ima_two[7],ing_ima_three[7]};
        arr_picmd5code = arrayRemoveSpace(arr_picmd5code);

        String[] address=new String[]{before_ima[8], ing_ima[8], after_ima[8], idcard_ima[8], fodoor_ima[8],ing_ima_two[8],ing_ima_three[8]};
        address=arrayRemoveSpace(address);

        String[] lw=new String[]{before_ima[9], ing_ima[9], after_ima[9], idcard_ima[9], fodoor_ima[9],ing_ima_two[9],ing_ima_three[9]};
        lw=arrayRemoveSpace(lw);


        fdIentity.setAdjunct_id(arr_adjunct_id);
        fdIentity.setSys_file_name(arr_sys_file_name);
        fdIentity.setAdjunct_type(arr_adjunct_type);
        fdIentity.setFile_type(arr_file_type);
        fdIentity.setFile_size(arr_file_size);
        fdIentity.setFile_des(arr_file_des);
        fdIentity.setUser_file_name(arr_user_file_name);
        fdIentity.setPicmd5code(arr_picmd5code);
        fdIentity.setAddress(address);
        fdIentity.setLw(lw);

        HttpUtils.requestPostGson(_mActivity, savecommitUrl, fdIentity, new Request() {

            @Override
            public void success(String jsonStr) {
                super.success(jsonStr);

                LogUtils.i("保存上传", "success: " + jsonStr);
                FIleEditSaveUpEntity fileeditip = GsonTools.changeGsonToBean(jsonStr, FIleEditSaveUpEntity.class);

                if (fileeditip != null && "success".equals(fileeditip.getState())) {
                    Toast.makeText(_mActivity, "保存成功!", Toast.LENGTH_SHORT).show();


                    //图片状态重置
                    sellIvMyFileOne.setVisibility(View.VISIBLE);
                    sellIvMyFileTwo.setVisibility(View.VISIBLE);
                    sellIvMyFileThree.setVisibility(View.VISIBLE);
                    sellIvMyFileFour.setVisibility(View.VISIBLE);
                    sellIvMyFileFive.setVisibility(View.VISIBLE);
                    image_show_B.setVisibility(View.GONE);
                    image_show_M.setVisibility(View.GONE);
                    image_show_F.setVisibility(View.GONE);
                    image_show_ID.setVisibility(View.GONE);
                    image_show_D.setVisibility(View.GONE);

                    //比如 未改造 设置为 已改造 时,刷新界面,状态改变
                    EventBus.getDefault().post(new MessageEvent("370"));
                    //返回列表页
                    _mActivity.onBackPressed();
                } else {
                    Toast.makeText(_mActivity, "更新失败", Toast.LENGTH_SHORT).show();
                }
                cancelLoadingDialog();
            }

            @Override
            public void error(String error) {
                super.error(error);
                LogUtils.i("保存上传", "error: " + error);
                cancelLoadingDialog();
            }

        });

    }

    private String[] arrayRemoveSpace(String[] arr_adjunct_id) {

        List<String> adjunct_id = new ArrayList<>();
        for (int i = 0; i < arr_adjunct_id.length; i++) {
            if (arr_adjunct_id[i] != null) {
                adjunct_id.add(arr_adjunct_id[i]);
            }
        }
        arr_adjunct_id = adjunct_id.toArray(new String[adjunct_id.size()]);

        return arr_adjunct_id;

    }

    private class CommitRequest extends Request {
        @Override
        public void success(String jsonStr) {
            super.success(jsonStr);

            LogUtils.i("保存上传", "success: " + jsonStr);
            FIleEditSaveUpEntity fileeditip = GsonTools.changeGsonToBean(jsonStr, FIleEditSaveUpEntity.class);

            if (fileeditip != null && "success".equals(fileeditip.getState())) {
                Toast.makeText(_mActivity, "保存成功!", Toast.LENGTH_SHORT).show();


                //图片状态重置
                sellIvMyFileOne.setVisibility(View.VISIBLE);
                sellIvMyFileTwo.setVisibility(View.VISIBLE);
                sellIvMyFileThree.setVisibility(View.VISIBLE);
                sellIvMyFileFour.setVisibility(View.VISIBLE);
                sellIvMyFileFive.setVisibility(View.VISIBLE);
                image_show_B.setVisibility(View.GONE);
                image_show_M.setVisibility(View.GONE);
                image_show_F.setVisibility(View.GONE);
                image_show_ID.setVisibility(View.GONE);
                image_show_D.setVisibility(View.GONE);

                //返回列表页
                _mActivity.onBackPressed();

                cancelLoadingDialog();
            }


        }

        @Override
        public void error(String error) {
            super.error(error);
            LogUtils.i("保存上传", "error: " + error);

            cancelLoadingDialog();
        }
    }

    /**
     * 显示listpopuwindow,并使用回调,显示数据
     *
     * @param view
     * @param mPopupWindow
     * @param datalist
     */
    private void setPopuData(View view, final ListPopupWindow mPopupWindow, final List<String> datalist) {
        ArrayAdapter<String> adapter = new ArrayAdapter<>(_mActivity, android.R.layout.simple_list_item_1, datalist);
        mPopupWindow.setAdapter(adapter);

        //弹出的位置  弹出锚点
        mPopupWindow.setAnchorView(view);
        //设置宽高
        mPopupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        mPopupWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);

        mPopupWindow.setModal(true);//设置模态框，设置为true响应物理键
        //设置条目点击事件
        mPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                //使用回调,显示数据
                if (popuClickListener != null) {
                    popuClickListener.show("" + datalist.get(position));
                }
                mPopupWindow.dismiss();
            }
        });
        mPopupWindow.show();
    }

    public PopuClickListener popuClickListener;

    public void setPopuClickListener(PopuClickListener popuClickListener) {
        this.popuClickListener = popuClickListener;
    }

    /**
     * 页面加载结束,请求数据
     *
     * @param savedInstanceState
     */
    @Override
    public void onEnterAnimationEnd(Bundle savedInstanceState) {
        super.onEnterAnimationEnd(savedInstanceState);

        showPermission();

        requestRefresh();

        initListener();

    }

    private void initListener() {


    }

    /**
     * eventbus 页面跳转,事件接受
     * 只接受事件跳转,不执行数据请求
     *
     * @param center
     */
    @Subscribe
    public void onEventReceive(EventCenter center) {


    }

    /**
     * 进入详情页 请求数据
     */
    private void requestRefresh() {
        String buildfile_detial = HttpApis.file_detile_head + getdataBean.getGaizao_id();

        LogUtils.i("档案详情", "requestRefresh: " + buildfile_detial);

        if (fileDetialRequest == null) {

            fileDetialRequest = new FileDetialRequest();
        }

        showLoadingDialog();
        HashMap<String, String> map = new HashMap<>();
        map.put("token",token_data);

        HttpUtils.requestGet(_mActivity, buildfile_detial,map, fileDetialRequest);


        //获取图片数据
        getBuildImageData(getdataBean.getGaizao_id());


    }

    /**
     * 获取图片数据
     *
     * @param gaizao_id
     */
    private void getBuildImageData(String gaizao_id) {
        String build_image_data = HttpApis.build_image_data;//+acceptid

        LogUtils.i("档案详情图片数据", build_image_data + "~~~" + gaizao_id);
        Map<String, String> params = new TreeMap<>();
        params.put("mid", gaizao_id);
        params.put("token",token_data);


        HttpUtils.requestPost(_mActivity, build_image_data, params, new Request() {
            @Override
            public void success(String jsonStr) {
                super.success(jsonStr);
                LogUtils.i("档案详情图片数据", jsonStr);
                Type type = new TypeToken<ArrayList<AcceptImageEntity>>() {
                }.getType();
                acceptImageEntities = JsonUtil.json2Collection(jsonStr, type);
                if (acceptImageEntities != null && acceptImageEntities.size() > 0) {
                    for (AcceptImageEntity acceptiamgedata : acceptImageEntities) {
                        processImageData(acceptiamgedata);
                        LogUtils.i("图片链接数据", acceptiamgedata.getSys_file_name());
                    }
                }
                cancelLoadingDialog();
            }

            @Override
            public void error(String error) {
                super.error(error);
                LogUtils.i("档案详情图片数据", error);
                cancelLoadingDialog();
            }
        });

    }

    /**
     * 加载请求下来的上传图片数据
     *
     * @param acceptiamgedata
     */
    private void processImageData(AcceptImageEntity acceptiamgedata) {
        switch (acceptiamgedata.getAdjunct_type()) {
            case "13":
                sellIvMyFileThree.setVisibility(View.GONE);
                image_show_B.setVisibility(View.VISIBLE);
                ImageLoaderUtils.setImageUrl(_mActivity, acceptiamgedata.getSys_file_name(), image_show_B);

                upAllBefore.setBackgroundResource(R.color.status_translate);

                before_ima[0] = acceptiamgedata.getAdjunct_id();
                before_ima[1] = acceptiamgedata.getSys_file_name();
                before_ima[2] = "13";//adjunct_type : 据上传图片定
                before_ima[3] = acceptiamgedata.getFile_type();
                before_ima[4] = acceptiamgedata.getFile_size();
                before_ima[5] = "改造前";//file_des:据上传图片定 身份证正面\大门照
                before_ima[6] = acceptiamgedata.getUser_file_name();
                before_ima[7] = acceptiamgedata.getPicmd5code();
                before_ima[8] = acceptiamgedata.getAddress();
                before_ima[9] = acceptiamgedata.getLw();

                isImageBfSuccess = true;
                break;
            case "1401":
                sellIvMyFileFour.setVisibility(View.GONE);
                image_show_M.setVisibility(View.VISIBLE);
                ImageLoaderUtils.setImageUrl(_mActivity, acceptiamgedata.getSys_file_name(), image_show_M);

                upAllIng.setBackgroundResource(R.color.status_translate);
                LogUtils.i("改造中图片数据", "processImageData: " + acceptiamgedata.getSys_file_name());

                ing_ima[0] = acceptiamgedata.getAdjunct_id();
                ing_ima[1] = acceptiamgedata.getSys_file_name();
                ing_ima[2] = "1401";//adjunct_type : 据上传图片定
                ing_ima[3] = acceptiamgedata.getFile_type();
                ing_ima[4] = acceptiamgedata.getFile_size();
                ing_ima[5] = "改造中";//file_des:据上传图片定 身份证正面\大门照
                ing_ima[6] = acceptiamgedata.getUser_file_name();
                ing_ima[7] = acceptiamgedata.getPicmd5code();
                ing_ima[8] = acceptiamgedata.getAddress();
                ing_ima[9] = acceptiamgedata.getLw();

                isImageMidSuccess = true;

                break;
            case "15":
                sellIvMyFileFive.setVisibility(View.GONE);
                image_show_F.setVisibility(View.VISIBLE);

                upAllAfter.setBackgroundResource(R.color.status_translate);

                ImageLoaderUtils.setImageUrl(_mActivity, acceptiamgedata.getSys_file_name(), image_show_F);

                after_ima[0] = acceptiamgedata.getAdjunct_id();
                after_ima[1] = acceptiamgedata.getSys_file_name();
                after_ima[2] = "15";//adjunct_type : 据上传图片定
                after_ima[3] = acceptiamgedata.getFile_type();
                after_ima[4] = acceptiamgedata.getFile_size();
                after_ima[5] = "改造后";//file_des:据上传图片定 身份证正面\大门照
                after_ima[6] = acceptiamgedata.getUser_file_name();
                after_ima[7] = acceptiamgedata.getPicmd5code();
                after_ima[8] = acceptiamgedata.getAddress();
                after_ima[9] = acceptiamgedata.getLw();

                isImageAfSuccess = true;

                break;
            case "11":
                sellIvMyFileOne.setVisibility(View.GONE);
                image_show_ID.setVisibility(View.VISIBLE);

                Glide.with(_mActivity)
                        .load(acceptiamgedata.getSys_file_name())
                        .into(image_show_ID);
                idcard_ima[0] = acceptiamgedata.getAdjunct_id();
                idcard_ima[1] = acceptiamgedata.getSys_file_name();
                idcard_ima[2] = "11";//adjunct_type : 据上传图片定
                idcard_ima[3] = acceptiamgedata.getFile_type();
                idcard_ima[4] = acceptiamgedata.getFile_size();
                idcard_ima[5] = "身份证";//file_des:据上传图片定 身份证正面\大门照
                idcard_ima[6] = acceptiamgedata.getUser_file_name();
                idcard_ima[7] = acceptiamgedata.getPicmd5code();
                idcard_ima[8] = acceptiamgedata.getAddress();
                idcard_ima[9] = acceptiamgedata.getLw();

                isImageIdSuccess = true;

                break;
            case "12":
                sellIvMyFileTwo.setVisibility(View.GONE);
                image_show_D.setVisibility(View.VISIBLE);
                ImageLoaderUtils.setImageUrl(_mActivity, acceptiamgedata.getSys_file_name(), image_show_D);


                fodoor_ima[0] = acceptiamgedata.getAdjunct_id();
                fodoor_ima[1] = acceptiamgedata.getSys_file_name();
                fodoor_ima[2] = "12";//adjunct_type : 据上传图片定
                fodoor_ima[3] = acceptiamgedata.getFile_type();
                fodoor_ima[4] = acceptiamgedata.getFile_size();
                fodoor_ima[5] = "大门照";//file_des:据上传图片定 身份证正面\大门照
                fodoor_ima[6] = acceptiamgedata.getUser_file_name();
                fodoor_ima[7] = acceptiamgedata.getPicmd5code();
                fodoor_ima[8] = acceptiamgedata.getAddress();
                fodoor_ima[9] = acceptiamgedata.getLw();

                isImageDoorFontSuccess = true;
                break;

            case "1402":
                sellIvDanganGaizaotwo.setVisibility(View.GONE);
                imageShowDanganGaizaotwo.setVisibility(View.VISIBLE);
                ImageLoaderUtils.setImageUrl(_mActivity, acceptiamgedata.getSys_file_name(), imageShowDanganGaizaotwo);

                ing_ima_two[0] = acceptiamgedata.getAdjunct_id();
                ing_ima_two[1] = acceptiamgedata.getSys_file_name();
                ing_ima_two[2] = "1402";//adjunct_type : 据上传图片定
                ing_ima_two[3] = acceptiamgedata.getFile_type();
                ing_ima_two[4] = acceptiamgedata.getFile_size();
                ing_ima_two[5] = acceptiamgedata.getFile_des();//file_des:据上传图片定 身份证正面\大门照
                ing_ima_two[6] = acceptiamgedata.getUser_file_name();
                ing_ima_two[7] = acceptiamgedata.getPicmd5code();
                ing_ima_two[8] = acceptiamgedata.getAddress();
                ing_ima_two[9] = acceptiamgedata.getLw();

                isImageingTwoSuccess=true;

                break;

            case "1403":

                sellIvDanganGaizaothree.setVisibility(View.GONE);
                imageShowDanganGaizaothree.setVisibility(View.VISIBLE);
                ImageLoaderUtils.setImageUrl(_mActivity, acceptiamgedata.getSys_file_name(), imageShowDanganGaizaothree);

                ing_ima_three[0] = acceptiamgedata.getAdjunct_id();
                ing_ima_three[1] = acceptiamgedata.getSys_file_name();
                ing_ima_three[2] = "1403";//adjunct_type : 据上传图片定
                ing_ima_three[3] = acceptiamgedata.getFile_type();
                ing_ima_three[4] = acceptiamgedata.getFile_size();
                ing_ima_three[5] = acceptiamgedata.getFile_des();//file_des:据上传图片定 身份证正面\大门照
                ing_ima_three[6] = acceptiamgedata.getUser_file_name();
                ing_ima_three[7] = acceptiamgedata.getPicmd5code();
                ing_ima_three[8] = acceptiamgedata.getAddress();
                ing_ima_three[9] = acceptiamgedata.getLw();

                isImageingThreeSuccess=true;

                break;

            default:

                break;
        }

    }

    /**
     * 获取详情数据
     */
    private class FileDetialRequest extends Request {
        @Override
        public void success(String jsonStr) {
            super.success(jsonStr);

            LogUtils.i("档案详情", "success: " + jsonStr);

            fileDetialEntity = GsonTools.changeGsonToBean(jsonStr, FileDetialEntity.class);

            if (fileDetialEntity != null) {
                processSetData(fileDetialEntity);
                cancelLoadingDialog();
            }

        }

        @Override
        public void error(String error) {
            super.error(error);
            LogUtils.i("档案详情", "error: " + error);
            cancelLoadingDialog();
        }
    }

    /**
     * 加载详情数据
     *
     * @param fileDetialEntity
     */
    private void processSetData(FileDetialEntity fileDetialEntity) {

        //=======================================

        fdIentity.setIdfield("gaizao_id");
        fdIentity.setAdjunct("1");
        fdIentity.setGaizao_state_n(fileDetialEntity.getGaizao_state_n());
        fdIentity.setGaizao_type_n(fileDetialEntity.getGaizao_type_n());
        fdIentity.setShgd_name(fileDetialEntity.getShgd_name());
        fdIentity.setHfc_material_n(fileDetialEntity.getHfc_material_n());
        fdIentity.setGaizao_fangshi_n(fileDetialEntity.getGaizao_fangshi_n());
        fdIentity.setBianchi_n(fileDetialEntity.getBianchi_n());
        fdIentity.setChongshuifangshi_n(fileDetialEntity.getChongshuifangshi_n());
        fdIentity.setCefang(fileDetialEntity.getCefang());
        fdIentity.setCefang_n(fileDetialEntity.getCefang_n());
        fdIentity.setXianzhi_n(fileDetialEntity.getXianzhi_n());
        fdIentity.setUpt_time(fileDetialEntity.getNow());
        fdIentity.setOld_gaizao_state(fileDetialEntity.getGaizao_state());
        fdIentity.setOld_xianzhi(fileDetialEntity.getXianzhi());
        fdIentity.setShi_area_id(fileDetialEntity.getArea_id());
        fdIentity.setAdj_table_info("bill_adjunct$business_id");
        fdIentity.setUpdate_count(fileDetialEntity.getGz_update_count());


        //=======================================

        //辖区单位
        acceptanceEtAddress.setText(fileDetialEntity.getArea_name() + "");
        fdIentity.setArea_name(fileDetialEntity.getArea_name());
        fdIentity.setArea_id(fileDetialEntity.getArea_id());
        //这里存储地区id,便于获取施工队伍数据
        SPUtil.putString(Constants.EDITAREAID, fileDetialEntity.getArea_id());
        //门牌号
        acceptanceEtDoorcode.setText(fileDetialEntity.getMenpaihao());
        fdIentity.setMenpaihao(fileDetialEntity.getMenpaihao());
        //户名
        acceptanceEtDoorname.setText(fileDetialEntity.getHuming());
        fdIentity.setHuming(fileDetialEntity.getHuming());
        //家庭人口
        etHunmanNumbers.setText(fileDetialEntity.getRenkou());
        fdIentity.setRenkou(fileDetialEntity.getRenkou());
        //联系电话
        etFileTel.setText(fileDetialEntity.getPhone());
        fdIentity.setPhone(fileDetialEntity.getPhone());

        //户编号
        acceptanceEtDoornumberning.setText(fileDetialEntity.getHubianhao());
        fdIentity.setHubianhao(fileDetialEntity.getHubianhao());
        //身份证号
        acceptanceEtIdnumber.setText(fileDetialEntity.getCert_no());
        fdIentity.setCert_no_sec(fileDetialEntity.getCert_no());
        //是否闲置
        acceptanceTvIsIdel.setText(fileDetialEntity.getXianzhi_n());
        fdIentity.setXianzhi(fileDetialEntity.getXianzhi());
        fdIentity.setXianzhi_n(fileDetialEntity.getXianzhi_n());
        if ("是".equals(fileDetialEntity.getXianzhi_n())) {
            acceptance_tv_stype.setEnabled(false);
        }
        if("".equals(fileDetialEntity.getXianzhi_n())||" ".equals(fileDetialEntity.getXianzhi_n())){
            fdIentity.setXianzhi("0");
            fdIentity.setXianzhi_n("否");
        }
        //改造状态
        acceptanceTvBuildstate.setText(fileDetialEntity.getGaizao_state_n());
        //根据改造状态显示其他内容
        UpShowForState(fileDetialEntity.getGaizao_state_n());

        if("已改造".equals(fileDetialEntity.getGaizao_state_n())||"旧有改造".equals(fileDetialEntity.getGaizao_state_n())){
            acceptanceTvBuildstate.setEnabled(false);
            acceptanceTvBuildstate.setClickable(false);



        }

//        if("已改造".equals(fileDetialEntity.getGaizao_state_n())){
//            acceptanceBtSave.setClickable(false);
//            acceptanceBtSave.setEnabled(false);
//            acceptanceBtSave.setBackgroundResource(R.drawable.toilet_sliding_tv_unselected);
//        }
        //isEditableBuildStyle(fileDetialEntity.getGaizao_state_n());
        fdIentity.setGaizao_state(fileDetialEntity.getGaizao_state());

        if(!TextUtils.isEmpty(fileDetialEntity.getGaizao_state())){
            SPUtil.putString(Constants.OLD_GAIZAO_STATE,fileDetialEntity.getGaizao_state());
        }

        fdIentity.setGaizao_state_n(fileDetialEntity.getGaizao_state_n());

        //改造类型
        acceptanceTvBuildtype.setText(fileDetialEntity.getGaizao_type_n());
        fdIentity.setGaizao_type(fileDetialEntity.getGaizao_type());
        fdIentity.setGaizao_type_n(fileDetialEntity.getGaizao_type_n());

        //改厕放式  gaizao_fangshi gaizao_fangshi_n
        acceptance_tv_stype.setText(fileDetialEntity.getGaizao_fangshi_n());
        fdIentity.setGaizao_fangshi(fileDetialEntity.getGaizao_fangshi());
        fdIentity.setGaizao_fangshi_n(fileDetialEntity.getGaizao_fangshi_n());

        //任务年份
        String stat_year = fileDetialEntity.getStat_year();
        if (!"-1".equals(stat_year)) {
            if("2019".equals(stat_year)){
                acceptanceTvBuildyear.setText(fileDetialEntity.getStat_year_n());
                fdIentity.setStat_year_n("2020年之前");
            }else if("2020".equals(stat_year)){
                acceptanceTvBuildyear.setText(fileDetialEntity.getStat_year_n());
                fdIentity.setStat_year_n("2020年");
            }

            fdIentity.setStat_year(fileDetialEntity.getStat_year());
        } else { // acceptanceTvBuildyear.setText(buildyearlist.get(1));
            //如果是空的,则设置默认值
            acceptanceTvBuildyear.setText(buildyearlist.get(1));
            fdIentity.setStat_year(buildyearlist.get(1));
        }


        //施工队
        acceptanceTvTeamname.setText(fileDetialEntity.getShgd_name());
        fdIentity.setShgd_id(fileDetialEntity.getShgd_id());
        fdIentity.setShgd_name(fileDetialEntity.getShgd_name());
        //化粪池
        acceptance_tv_huaFeiChi.setText(fileDetialEntity.getHfc_material_n());
        fdIentity.setHfc_material(fileDetialEntity.getHfc_material());
        fdIentity.setHfc_material_n(fileDetialEntity.getHfc_material_n());
        //便池类型
        fileBianchiTv.setText(fileDetialEntity.getBianchi_n());
        fdIentity.setBianchi(fileDetialEntity.getBianchi());
        fdIentity.setBianchi_n(fileDetialEntity.getBianchi_n());
        //冲水方式
        fileChongshuiTv.setText(fileDetialEntity.getChongshuifangshi_n());
        fdIentity.setChongshuifangshi(fileDetialEntity.getChongshuifangshi());
        fdIentity.setChongshuifangshi_n(fileDetialEntity.getChongshuifangshi_n());

        //厕房类型
        fileCefangTv.setText(fileDetialEntity.getCefang_n());
        String cefang = fileDetialEntity.getCefang();
        if(cefang!=null){
            if(cefang.contains("[")){
                cefang=StringUtil.deleteCharString(cefang,'[');
            }
            if(cefang.contains("]")){
                cefang=StringUtil.deleteCharString(cefang,']');
            }
            if(cefang.contains(" ")){
                cefang=StringUtil.deleteCharString(cefang,' ');
            }
        }
        fdIentity.setCefang(cefang);
        String cefang_n = fileDetialEntity.getCefang_n();
        if(cefang_n!=null){
            if(cefang_n.contains("[")){
                cefang_n= StringUtil.deleteCharString(cefang_n,'[');
            }
            if(cefang_n.contains("]")){
                cefang_n= StringUtil.deleteCharString(cefang_n,']');
            }
            if(cefang_n.contains(" ")){
                cefang_n= StringUtil.deleteCharString(cefang_n,' ');
            }
        }
        fdIentity.setCefang_n(cefang_n);

        fdIentity.setUpdate_count(fileDetialEntity.getGz_update_count());


    }


    /**
     * 点击添加图片,并同时是上传图片选择
     */
    private void showPhotoPic() {
        String carrier = Build.MANUFACTURER;
        LogUtils.i("手机厂商", "showPhotoPic: " + carrier);
        showPhotoPicker();
    }

    /**
     * 获取图库返回的图片
     *
     * @param requestCode
     * @param resultCode
     * @param data
     */
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        LogUtils.i("返回的code值", "onActivityResult: requestCode:" + requestCode + "~~resultCode:" + resultCode);

        if (resultCode == RESULT_OK && requestCode == PhotoPicker.REQUEST_CODE && data != null) {
            LogUtils.e("显示", "onActivityResult");

            ArrayList<String> photos = data.getStringArrayListExtra(PhotoPicker.KEY_SELECTED_PHOTOS);

            //=========添加水印=========
            String absolutePath = photos.get(0);
            if (absolutePath.endsWith(":abc") && mLayoutType != 4) {
                absolutePath = absolutePath.substring(0, absolutePath.length() - 4);
                savePic(absolutePath);
            }
            //==========添加水印========
            showLoadingDialog("正在上传图片");
            for (int i = 0; i < photos.size(); i++) {
                String uri = Uri.decode(photos.get(i));
                if (uri.endsWith(":abc")) {
                    uri = uri.substring(0, uri.length() - 4);
                }
                LogUtils.e("uri", uri);
                try {
                    compressWithRx(new File(uri));
                } catch (Exception e) {
                    Toast.makeText(_mActivity, "请重新上传", Toast.LENGTH_SHORT).show();
                }
            }
        }
    }

    private void savePic(String filename) {

        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inPurgeable = true;
        options.inSampleSize = 2;
        Bitmap bm = BitmapFactory.decodeFile(filename, options);


        File file = new File(filename);

        try {
            FileOutputStream fos = new FileOutputStream(file);
            String time = netTime;
            String address = MyApplication.getAddress();
            if (address == null) {
                address = "";
            }
            String content = time + ";" + address;
            Bitmap newbm = ImageUtils.drawTextToRightBottom(_mActivity, bm, content,
                    25, ContextCompat.getColor(_mActivity, R.color.show2), 10, 10);
            newbm.compress(Bitmap.CompressFormat.JPEG, 100, fos);// 把数据写入文件
            fos.flush();
            fos.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    /**
     * 添加时间水印
     *
     * @param bm
     */
    private Bitmap addTimeFlag(Context context, Bitmap bm) {
        // 获取原始图片与水印图片的宽与高
        int w = bm.getWidth();
        int h = bm.getHeight();
        Bitmap newBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
        Canvas mCanvas = new Canvas(newBitmap);
        // 往位图中开始画入src原始图片
        mCanvas.drawBitmap(bm, 0, 0, null);
        //添加文字
        Paint textPaint = new Paint();
        textPaint.setColor(ContextCompat.getColor(context, R.color.show2));
        textPaint.setTextSize(200);
        Path path = new Path();
        path.moveTo(w / 6, h - h * 5 / 9);
        path.lineTo(w - w / 6, 200);
        // 绘制路径
        mCanvas.drawPath(path, textPaint);
        mCanvas.drawTextOnPath(MyApplication.getAddress(), path, 0f, 0f, textPaint);
        mCanvas.save();
        mCanvas.restore();
        return newBitmap;
    }

    /**
     * 压缩单张图片 RxJava 方式
     */
    private void compressWithRx(File file) {
        Flowable.just(file)
                .observeOn(Schedulers.io())
                .map(new Function<File, File>() {
                    @Override
                    public File apply(@NonNull File file) {//  throws Exception
                        try {
                            File file1 = Luban.with(_mActivity).load(file).get();
                            return file1;
                        } catch (Exception e) {
                            //对于文件损坏的文件/压缩失败的文件,也能上传,但是,在主线程中提示
                            //记住,修改权限
                            _mActivity.runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    showShortToast("请重新上传");
                                }
                            });

                            return file;
                        }

                    }
                })
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<File>() {
                    @Override
                    public void accept(@NonNull File file) {
                        LogUtils.e("fileinfo", "file- " + file.length() / 1024 + "k" + " name- " + file.getName() + " paht- " + file.getPath());
                        //上传图片
                        if (file == null) {
                            Toast.makeText(_mActivity, "请重新上传", Toast.LENGTH_SHORT).show();
                        } else {
                            uploadImgFile(file, file.getName(), file.getPath());
                        }
                    }
                });
    }


    /**
     * 上传单张图片
     *
     * @param file
     * @param fileName
     */
    private void uploadImgFile(final File file, final String fileName, final String filepath) {
        String url = HttpApis.upload_image;
        Map<String, String> params = new HashMap<>();
        String location_str = MyApplication.getAddress();
        if (location_str != null && location_str.contains(";")) {
            String[] split = location_str.split(";");
            if (split[0] != null) {
                params.put("address", split[0]);
            }
            if (split[1] != null) {
                String jingwei=split[1];
                if(jingwei.contains("经")){
                    jingwei=StringUtil.deleteCharString(jingwei,'经');
                }
                if(jingwei.contains("度")){
                    jingwei=StringUtil.deleteCharString(jingwei,'度');
                }
                if(jingwei.contains(":")){
                    jingwei=StringUtil.deleteCharString(jingwei,':');
                }
                if(jingwei.contains("纬")){
                    jingwei=jingwei.replace("纬",",");
                }
                params.put("lw", jingwei);
                //params.put("lw", split[1]);
            }
        }
        params.put("token",token_data);
        HttpUtils.requestPostFileUploadesLocation(getActivity(), url, fileName, file, params, new Request() {
            @Override
            public void success(String jsonStr) {
                super.success(jsonStr);
                LogUtils.e("上传图片成功detial", "jsonSuccess  " + jsonStr);
                UploadImageEntity uploadImageEntity = GsonTools.changeGsonToBean(jsonStr, UploadImageEntity.class);
                if ("SUCCESS".equals(uploadImageEntity.getState())) {
                    LogUtils.i("mLayoutType", "success: " + mLayoutType);
                    if (mLayoutType == 4) {
                        uploadImageEntity.setIsrepeat("0");
                    }


                    if(imageName.contains(uploadImageEntity.getPicmd5code())){
                        showAlertOnlyPos(_mActivity,"图片上传","图片上传重复,请重新上传");
                        isUploadSuccess = false;

                    }else{
                        imageName.add(uploadImageEntity.getPicmd5code());
                        if ("0".equals(uploadImageEntity.getIsrepeat())) {//0表示不重复  1表示重复
                            isUploadSuccess = true;
                            displayUploadImgFile(uploadImageEntity, fileName,params);  //将img显示
                        } else {
                            //showShortToast("图片上传重复,请重新上传");
                            showAlertOnlyPos(_mActivity, "图片上传", "图片上传重复,请重新上传");
                            isUploadSuccess = false;
                        }
                    }



                } else {
                    //showShortToast("上传失败，图片大小不能超过4兆");
                    showAlertOnlyPos(_mActivity, "图片上传", "上传失败，图片大小不能超过4兆");
                    isUploadSuccess = false;
                }
                cancelLoadingDialog();
            }

            @Override
            public void error(String error) {
                super.error(error);
                isUploadSuccess = false;
                cancelLoadingDialog();
            }
        });

    }


    /**
     * 显示预览图片
     *
     * @param uploadImageEntity
     */
    private void displayUploadImgFile(UploadImageEntity uploadImageEntity, String fileName,Map<String, String> params) {
        //图片修改功能，需要传一个固定字段值,      解决不能删除全部图片问题。
        fdIentity.setAdj_table_info("bill_adjunct$business_id");
        String address=params.get("address");
        String lw=params.get("lw");
        switch (mLayoutType) {
            case 1:
                sellIvMyFileThree.setVisibility(View.GONE);
                image_show_B.setVisibility(View.VISIBLE);
                LogUtils.i("上传图片成功", "展示图片 1 " + uploadImageEntity.getFilePath());
                Glide.with(_mActivity).load(uploadImageEntity.getFilePath())
                        .into(image_show_B);
                upAllBefore.setBackgroundResource(R.color.status_translate);
                before_ima[0] = uploadImageEntity.getFileID();
                before_ima[1] = uploadImageEntity.getFilePath();
                before_ima[2] = "13";//adjunct_type : 据上传图片定
                before_ima[3] = uploadImageEntity.getFileExt();
                before_ima[4] = uploadImageEntity.getSize();
                before_ima[5] = "改造前";//file_des:据上传图片定 身份证正面\大门照
                before_ima[6] = fileName;
                before_ima[7] = uploadImageEntity.getPicmd5code();
                before_ima[8] = address;
                before_ima[9] = lw;
                if (isUploadSuccess) {
                    isImageBfSuccess = isUploadSuccess;
                }
                break;
            case 2:
                sellIvMyFileFour.setVisibility(View.GONE);
                image_show_M.setVisibility(View.VISIBLE);
                LogUtils.i("上传图片成功", "展示图片 2 " + uploadImageEntity.getFilePath());
                Glide.with(_mActivity).load(uploadImageEntity.getFilePath()).into(image_show_M);
                upAllIng.setBackgroundResource(R.color.status_translate);
                ing_ima[0] = uploadImageEntity.getFileID();
                ing_ima[1] = uploadImageEntity.getFilePath();
                ing_ima[2] = "1401";//adjunct_type : 据上传图片定
                ing_ima[3] = uploadImageEntity.getFileExt();
                ing_ima[4] = uploadImageEntity.getSize();
                ing_ima[5] = "改造中";//file_des:据上传图片定 身份证正面\大门照
                ing_ima[6] = fileName;
                ing_ima[7] = uploadImageEntity.getPicmd5code();
                ing_ima[8] = address;
                ing_ima[9] = lw;
                if (isUploadSuccess) {
                    isImageMidSuccess = isUploadSuccess;
                }
                break;
            case 3:
                sellIvMyFileFive.setVisibility(View.GONE);
                image_show_F.setVisibility(View.VISIBLE);
                Glide.with(_mActivity).load(uploadImageEntity.getFilePath()).into(image_show_F);
                upAllAfter.setBackgroundResource(R.color.status_translate);
                after_ima[0] = uploadImageEntity.getFileID();
                after_ima[1] = uploadImageEntity.getFilePath();
                after_ima[2] = "15";//adjunct_type : 据上传图片定
                after_ima[3] = uploadImageEntity.getFileExt();
                after_ima[4] = uploadImageEntity.getSize();
                after_ima[5] = "改造后";//file_des:据上传图片定 身份证正面\大门照
                after_ima[6] = fileName;
                after_ima[7] = uploadImageEntity.getPicmd5code();
                after_ima[8] = address;
                after_ima[9] = lw;
                if (isUploadSuccess) {
                    isImageAfSuccess = isUploadSuccess;
                }
                break;
            case 4:
                sellIvMyFileOne.setVisibility(View.GONE);
                image_show_ID.setVisibility(View.VISIBLE);
                Glide.with(_mActivity).load(uploadImageEntity.getFilePath()).into(image_show_ID);
                idcard_ima[0] = uploadImageEntity.getFileID();
                idcard_ima[1] = uploadImageEntity.getFilePath();
                idcard_ima[2] = "11";//adjunct_type : 据上传图片定
                idcard_ima[3] = uploadImageEntity.getFileExt();
                idcard_ima[4] = uploadImageEntity.getSize();
                idcard_ima[5] = "身份证";//file_des:据上传图片定 身份证正面\大门照
                idcard_ima[6] = fileName;
                idcard_ima[7] = uploadImageEntity.getPicmd5code();
                idcard_ima[8] = address;
                idcard_ima[9] = lw;
                if (isUploadSuccess) {
                    isImageIdSuccess = isUploadSuccess;
                }
                break;
            case 5:
                sellIvMyFileTwo.setVisibility(View.GONE);
                image_show_D.setVisibility(View.VISIBLE);
                Glide.with(_mActivity).load(uploadImageEntity.getFilePath()).into(image_show_D);
                fodoor_ima[0] = uploadImageEntity.getFileID();
                fodoor_ima[1] = uploadImageEntity.getFilePath();
                fodoor_ima[2] = "12";//adjunct_type : 据上传图片定
                fodoor_ima[3] = uploadImageEntity.getFileExt();
                fodoor_ima[4] = uploadImageEntity.getSize();
                fodoor_ima[5] = "大门照";//file_des:据上传图片定 身份证正面\大门照
                fodoor_ima[6] = fileName;
                fodoor_ima[7] = uploadImageEntity.getPicmd5code();
                fodoor_ima[8] = address;
                fodoor_ima[9] = lw;
                if (isUploadSuccess) {
                    isImageDoorFontSuccess = isUploadSuccess;
                }
                break;

            case 6:
                sellIvDanganGaizaotwo.setVisibility(View.GONE);
                imageShowDanganGaizaotwo.setVisibility(View.VISIBLE);
                Glide.with(_mActivity).load(uploadImageEntity.getFilePath()).into(imageShowDanganGaizaotwo);
                ing_ima_two[0] = uploadImageEntity.getFileID();
                ing_ima_two[1] = uploadImageEntity.getFilePath();
                ing_ima_two[2] = "1402";//adjunct_type : 据上传图片定
                ing_ima_two[3] = uploadImageEntity.getFileExt();
                ing_ima_two[4] = uploadImageEntity.getSize();
                ing_ima_two[5] = "补充照片1";//file_des:据上传图片定 身份证正面\大门照
                ing_ima_two[6] = fileName;
                ing_ima_two[7] = uploadImageEntity.getPicmd5code();
                ing_ima_two[8] = address;
                ing_ima_two[9] = lw;
                if (isUploadSuccess) {
                    isImageingTwoSuccess = isUploadSuccess;
                }
                break;

            case 7:
                sellIvDanganGaizaothree.setVisibility(View.GONE);
                imageShowDanganGaizaothree.setVisibility(View.VISIBLE);
                Glide.with(_mActivity).load(uploadImageEntity.getFilePath()).into(imageShowDanganGaizaothree);
                ing_ima_three[0] = uploadImageEntity.getFileID();
                ing_ima_three[1] = uploadImageEntity.getFilePath();
                ing_ima_three[2] = "1403";//adjunct_type : 据上传图片定
                ing_ima_three[3] = uploadImageEntity.getFileExt();
                ing_ima_three[4] = uploadImageEntity.getSize();
                ing_ima_three[5] = "补充照片2";//file_des:据上传图片定 身份证正面\大门照
                ing_ima_three[6] = fileName;
                ing_ima_three[7] = uploadImageEntity.getPicmd5code();
                ing_ima_three[8] = address;
                ing_ima_three[9] = lw;
                if (isUploadSuccess) {
                    isImageingThreeSuccess = isUploadSuccess;
                }
                break;
            default:
                break;

        }

    }

    /**
     * 显示图片选择
     */
    private void showPhotoPicker() {

        PhotoPicker.builder()
                .setPhotoCount(1) //显示图片张
                .setPreviewEnabled(false)
                .start(_mActivity, this, PhotoPicker.REQUEST_CODE);
    }

    /**
     * 申请权限
     */
    private void showPermission() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (ContextCompat.checkSelfPermission(_mActivity, Manifest.permission.CAMERA)
                    != PackageManager.PERMISSION_GRANTED) {//  如果没有申请权限
                ActivityCompat.requestPermissions(_mActivity, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE,
                                Manifest.permission.READ_EXTERNAL_STORAGE,
                                Manifest.permission.WRITE_SETTINGS,
                                Manifest.permission.CAMERA},
                        REQUEST_CODE_SOME_FEATURES_PERMISSIONS);
            }
        }
    }

    /**
     * 权限回调
     *
     * @param requestCode
     * @param permissions
     * @param grantResults
     */
    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);

        switch (requestCode) {
            case REQUEST_CODE_SOME_FEATURES_PERMISSIONS: {
                System.out.println("Permissions --> " + permissions.length);
                for (int i = 0; i < permissions.length; i++) {
                    if (grantResults[i] == PackageManager.PERMISSION_GRANTED) {
                        System.out.println("Permissions --> " + "Permission Granted: " + permissions[i]);
                    } else if (grantResults[i] == PackageManager.PERMISSION_DENIED) {
                        System.out.println("Permissions     --> " + "Permission Denied: " + permissions[i]);
                        if (isShowDialog) {
                            isShowDialog = false;
                            showPermissionDialog();
                        }
                    }
                }
            }
            break;
            default: {
                super.onRequestPermissionsResult(requestCode, permissions, grantResults);
            }
        }

    }

    /**
     * 显示权限对话框
     */
    private void showPermissionDialog() {
        showAlertDialog(_mActivity, "权限申请", "为了您可以上传图片请打开此权限,点确认再次申请", new DialogClick() {
            @Override
            public void PositiveMessage() {
                showPermission();
            }

            @Override
            public void NegativeMessage() {
                showShortToast("您将无法上传图片信息");
                isShowDialog = true;
            }
        });
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
        EventBus.getDefault().unregister(this);
        OkHttpUtils.getInstance().cancelTag(this);
        cancelLoadingDialog();
    }
}
